-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from smswithoutborders/dev
Dev
- Loading branch information
Showing
16 changed files
with
285 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,36 @@ | ||
# SMSWithoutBorders - Android | ||
|
||
## Implementations | ||
### Publishing Payload | ||
```python3 | ||
pl = b'g' | ||
encrypted_content=b'...' | ||
device_id=b'...' | ||
|
||
### DeviceID | ||
payload = len(encrypted_content) + pl + encrypted_content + device_id | ||
return base64.encode(payload) | ||
|
||
**Requirements** | ||
|
||
- _secret_key_:- Derived from a DH handshake with Vault. Not used for any form of encryption for messaging sending. | ||
- _phone_number_:- Phone number used in creating Vault account. | ||
- _public_key_:- The Public key used in the DH handshake above. | ||
|
||
```python | ||
import hmac | ||
import hashlib | ||
|
||
def generate_device_id(secret_key, phone_number, public_key) -> bytes: | ||
# Combine the phone number and public key | ||
combined_input = phone_number + public_key | ||
|
||
# Create an HMAC object using the secret key and SHA-256 hash function | ||
hmac_object = hmac.new(secret_key.encode(), combined_input.encode(), hashlib.sha256) | ||
|
||
# Generate the device ID as a hexadecimal string | ||
return hmac_object | ||
#unpacking in Python | ||
import struct | ||
import base64 | ||
|
||
device_id = generate_device_id(...) | ||
payload = base64.decode(incoming_payload) | ||
len_enc_content = struct.unpack("<i", payload[0]) | ||
pl = payload[1] | ||
encrypted_content = payload[2:len_enc_content] | ||
device_id = payload[2+len_enc_content:] | ||
``` | ||
|
||
**Implementation considerations** | ||
|
||
- Proof of number ownership is required to avoid spoofing as another user. OTP via SMS when creating account can be used here. | ||
|
||
**Payload structure** | ||
```python | ||
import struct | ||
### Platform specific publications (encrypted content) | ||
```python3 | ||
""" Email (Gmail etc) | ||
""" | ||
# to:cc:bcc:subject:body | ||
|
||
# Encoding | ||
... | ||
ctLen = len(encrypted_content_bytes) | ||
payload = base64.encode(concat_bytes(struct.pack("<i", ctLen), encrypted_content_bytes, device_id)) | ||
""" Messages (Telegram etc) | ||
""" | ||
# to:body | ||
|
||
# Decoding | ||
... | ||
ctLen = int.from_bytes(payload[0:4]) | ||
cipher_text = payload[ctLen:-64] | ||
device_id = payload[-64:] | ||
""" Text (X; Twitter etc) | ||
""" | ||
# body | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.example.sw0b_001 | ||
|
||
import io.grpc.ManagedChannel | ||
import io.grpc.ManagedChannelBuilder | ||
import io.grpc.StatusRuntimeException | ||
import org.junit.Before | ||
import org.junit.Test | ||
import vault.v1.EntityGrpc | ||
import vault.v1.EntityGrpc.EntityBlockingStub | ||
import vault.v1.EntityGrpc.EntityFutureStub | ||
import vault.v1.EntityGrpc.EntityStub | ||
import vault.v1.Vault1.CreateEntityRequest | ||
import java.net.Inet6Address | ||
|
||
class gRPCTest { | ||
lateinit var channel: ManagedChannel | ||
lateinit var entityStub: EntityBlockingStub | ||
|
||
val globalPhoneNumber = "+237123456789" | ||
|
||
@Before | ||
fun init() { | ||
channel = ManagedChannelBuilder | ||
.forAddress("staging.smswithoutborders.com", 9050) | ||
.useTransportSecurity() | ||
.build() | ||
|
||
entityStub = EntityGrpc.newBlockingStub(channel) | ||
} | ||
|
||
@Test | ||
fun vaultTestCreateEntity() { | ||
val createEntityRequest1 = CreateEntityRequest.newBuilder().apply { | ||
setPhoneNumber(globalPhoneNumber) | ||
}.build() | ||
|
||
try { | ||
val createResponse = entityStub.createEntity(createEntityRequest1) | ||
assert(createResponse.requiresOwnershipProof) | ||
println(createResponse.message) | ||
} catch(e: Exception) { | ||
if(e is StatusRuntimeException) { | ||
when(e.status.code.toString()) { | ||
"INVALID_ARGUMENT" -> { | ||
println(e.message) | ||
throw e | ||
} | ||
"ALREADY_EXISTS" -> { | ||
println(e.message) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun vaultTestCreateEntity2() { | ||
vaultTestCreateEntity() | ||
val createEntityRequest2 = CreateEntityRequest.newBuilder().apply { | ||
setCountryCode("CM") | ||
setPhoneNumber(globalPhoneNumber) | ||
setPassword("dMd2Kmo9") | ||
setClientPublishPubKey("dMd2Kmo9") | ||
setClientDeviceIdPubKey("dMd2Kmo9") | ||
setOwnershipProofResponse("123456") | ||
}.build() | ||
|
||
try { | ||
val createResponse = entityStub.createEntity(createEntityRequest2) | ||
assert(createResponse.requiresOwnershipProof) | ||
println(createResponse.message) | ||
} catch(e: Exception) { | ||
if(e is StatusRuntimeException) { | ||
when(e.status.code.toString()) { | ||
"UNAUTHENTICATED" -> { | ||
println(e.message) | ||
} | ||
} | ||
} | ||
throw e | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.