• Stars
    star
    324
  • Rank 129,708 (Top 3 %)
  • Language
    C#
  • License
    GNU General Publi...
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ADAMANT push Notification Service for iOS Messenger app

ADAMANT Notification Service (ANS)

The first of ADAMANT Services, implemented to make secure instant notifications for ADAMANT iOS application.

Note: ADAMANT Blockchain and Messenger apps are fully functional without ANS and other Services. The goal of ADAMANT Services and ANS is to provide features that can not be implemented on the Blockchain. More on adamant.im.

How it works

To deliver notification privately and secure, 4 parties are involved:

  1. User's device (i. e., iPhone)
  2. ADAMANT's blockchain
  3. Apple Push Notification Service (APNS)
  4. This application, ADAMANT Notification Service (ANS)

A workflow runs as:

  • User sends an encrypted signal message with a unique token to an ADAMANT blockchain node. Recipient is ANS's ADAMANT address. See AIP-6: Signal Messages.
  • ANS polls the blockchain and decrypts the user's token
  • ANS polls the blockchain and filter transactions, where user's ADM address is the recipient. ANS asks APNS to deliver these transactions (they holds encrypted messages) to a user's device, specified by unique token.
  • APNS notifies a user's device
  • User's device has a secret key and decrypts messages

This way a user's device never communicate with ANS, and ANS don't know its IP or other identities. They communicate through a blockchain nodes.

ANS application

This application, ANS, consists of two main parts:

ANSSignalsRegistration — console application that polls ADAMANT blockchain nodes for new service signals to get device tokens. Message payload must be serialized in JSON and encrypted as other chat transactions.

Payload format:

{
    "token": "DeviceToken",
    "provider": "apns",
    "action": "add"
}
  • token: user's device token
  • provider: push service provider
    • apns: for release builds
    • apns-sandbox: for debug builds (not yet supported)
  • action (optional): signal action
    • add (default): register new devise
    • remove: unregister device

ANSPollingWorker — console application that polls ADAMANT nodes for new transactions and checks for registered devices of receivers. If there is a registered device for the recipient of the transaction—sends a notification.

QA

Device token? What about security?

You can read about Apple Push Notification Service (APNS) and security on Apple's docs.

In short:

  • We do not use third party services to send notifications. Your tokens and addresses doesn't fly around the Internet.
  • It's technically impossible to read a message contents from a transaction for ANS and it is impossible to include decrypted message into push contents. To decrypt a message, secret key is needed. And only user device holds it.
  • Starting from version 0.4, ANS includes txn-id param in the push content with the transaction id. A client app can get the transaction from a blockchain node and decrypt the message on the device, using a locally stored secret key. This is handled by NotificationServiceExtension, and a passphrase (secret key) is stored securely in a Keychain.
  • Your device token is unique for each application on your device. We can't find your facebook page with your device token, generated for the ADAMANT app.
  • New device token is generated each time you reinstall an app, or just re-enable notifications. You can just disable notifications for ADAMANT app, and the device token in ANS database becomes useless. Next time ANS will try to send a push notification, Apple will say the token is broken.

iOS App Badge?

In iOS, app's badge number is sent to you by a server as a part of a push notification, it's not handled by an application, as application can be even terminated and unloaded from memory at the moment. ANS doesn't know how many messages you haven't read. That's why ANS shows 1 badge, if there any unread messages. Alternative solution is to handle it locally on a device by the NotificationServiceExtension—an app extension, that can modify notification content.

Installation

.NET Core version

APNS requires HTTP/2 connection. dotnet core 2.1 and 2.2 does not support it. The app is build with is 3.0.100-preview5-011568, and it supports HTTP/2. You can create a self-contained build for a machine without 3.0 runtime on a machine with 3.0 SDK.

dotnet publish -c Release -r linux-64 -o {output path} -f netcoreapp3.0

more about -r, more about -f, download dotnet core SDK.

Want to try it out?

  1. You gonna need a dotnet.core runtime to launch ANS. Go to Microsoft.com and download SDK for your platform.
  2. Clone or download this repository
  3. Open terminal/console/cmd and type dotnet restore in the Solution's folder, or just open the Solution in Visual Studio. VS will automatically restore NuGet dependencies.
  4. Grab sample config file at Solution's root, edit your connection strings, nodes, delays, certificates, and save it to {UserHomeDirectory}/.ans/config.json. See Configuration.
  5. At first launch, the application will auto-upgrade your database.
  6. To launch ANSPollingWorker, you need your Apple Push certificate, you can grab it from Apple Developer's center. Place it in {UserHomeDirectory}/.ans/, make sure you've specified correct path and certificate's password in the config. Go to terminal, cd ANSPollingWorker, dotnet run.
  7. To launch ANSRegistrationService, type in your ANS account in the config. Go to terminal, cd ANSRegistrationService, dotnet run.
  8. You can run dotnet publish -c Release to create compiled archives. More about dotnet core, and what to do with this 'compiled archives' you can read on Microsoft.com.

You will need a certificate to send a push notifications to APNS, which you can get from your Apple Developer account.

My own iOS app and ANS server

If you are building your own iOS ADAMANT application and want to use your own ANS server, you will need to:

  1. Register ADAMANT account for ANS. Just a regular 'U' account.
  2. In iOS source code, type your ANS account's address and public key in AdamantResources struct.
  3. In ANS config, type in your ANS's ADM account address and private key. See Configuration.
  4. To create .pfx certificate with ECDSA private key. First, create a key and download it from your Apple Developer page. Put it in some folder. Open Terminal, navigate to this folder, and type:
openssl req -new -x509 -key key.p8 -out selfsigned.cer
openssl pkcs12 -export -in selfsigned.cer -inkey key.p8 -out cert.pfx

Put the .pfx certificate in ~/.ans, and update the config.

  1. Done. iOS application will send device tokens to your ANS ADM account, ANSRegistrationService will poll signal transactions and register tokens, and ANSPollingService will poll new messages/transactions and notify registered devices.

Configuration

Sample configuration file is located in the Solution's root directory. Both Polling ans Signal registration services loads config from ~/.ans/config.json, so you have one config file for ANS.

Config sections

  • Database (optional): Section for database configuration. Params:

    • ConnectionString (optional, default: devices). ConnectionString name. Strings is specified in ConnectionStrings section, see bellow.
    • Provider (optional): Database connection provider. Two providers are supported:
      • sqlite
      • mysql (default)
  • ConnectionStrings: a standard dotnet section for connection strings. Active connection string name specified in Database:ConnectionString param, default is devices.

  • Api: ADAMANT node settings.

    • Server[]: node addresses. Properties:
      • ip (string): node address (or ip)
      • protocol (string, optional, default: https)
      • port (int, optional)
  • PollingWorker: Polling settings. Properties:

    • Delay (milliseconds as int, optional, default: 2000): interval between two requests to retrieve new messages
    • NlogConfig (string, optional, default: nlog.config): path to NLog configuration file
    • Startup (enum, optional, default: database): Startup mode. Options:
      • database: Try to load saved last blockchain height from database, and start from this value. If failed or no value saved, switch to network mode.
      • network: Try to get last transaction from network and use its height as last height value. If failed or no transaction received, go to initial mode.
      • initial: Start from blockchain height 0.
  • SignalsRegistration: Signals polling & registration settings. Properties:

    • Delay (milliseconds as int, optional, default: 2000): interval between two requests to retrieve new signal transactions
    • NlogConfig (string, optional, default: nlog.config): path to NLog configuration file
    • Address (string, required): ANS's ADM account address to poll signals
    • PrivateKey (string, required): ANS's ADM account private key to decrypt signal transactions
    • Startup (enum, optional, default: database): Startup mode. Same options as for PollingWorker:Startup.
  • ApplePusher: APNS settings. Sections:

    • Keys. Properties:
      • keyId (string): Your developer key id. Created and obtained at your Auth Keys page.
      • teamId (string): Your app developer team id. Obtained at your Apple Dev Membership Details.
      • bundleAppId (string): Your application bundle id
      • pfxPath (string): Path to self-signed *.pfx certificate. Certificate must contain ECDSA private key
      • pfxPassword (string): Certificate's password
    • Certificate. Properties:
      • path (string): Path to APNS *.p12 certificate
      • pass (string): Certificate's password
    • Payload[]. Apple push notifications payload. Properties:
      • transactionType: 0 for ADM token transfer, 8 for chat transactions and coin transfers
      • title
      • body
      • sound

More Repositories

1

adamant

ADAMANT Blockchain Node
JavaScript
728
star
2

ETH-transactions-storage

Indexer for Ethereum to get transaction list by ETH address
Python
610
star
3

adamant-im

ADAMANT Decentralized Messenger. Progressive Web Application (PWA)
Vue
583
star
4

adamant-tradebot

Free self-hosted market-making software for cryptocurrency projects and exchanges. Makes trade volume, maintains spread and liquidity/depth, set price range, and builds live-like dynamic order book.
JavaScript
541
star
5

adamant-coinoptimus

Free self-hosted cryptocurrency trade bot for non-professional traders
JavaScript
378
star
6

pool

ADAMANT Forging pool with Web interface
JavaScript
352
star
7

adamant-api-jsclient

ADAMANT Javascript API library
TypeScript
349
star
8

adamant-exchangebot

Crypto exchange bot for ADAMANT
JavaScript
345
star
9

adamant-console

Command-line utilities to work with ADAMANT blockchain
JavaScript
342
star
10

adamant-explorer

ADAMANT Blockchain Explorer
JavaScript
338
star
11

adamant-iOS

iOS native client for ADAMANT Decentralized Messenger
Swift
337
star
12

adamant-2fa

ADAMANT's Blockchain 2FA demo
JavaScript
335
star
13

AIPs

ADAMANT Improvement Proposal repository
HTML
288
star
14

adamant-wallets

Unified coin/token specification for wallets in ADAMANT apps
Vue
282
star
15

adamant-schema

Swagger schema for ADAMANT node
TypeScript
263
star
16

adamant-currencyinfo-services

Self-hosted crypto and fiat currency rates service provider. MOEX, Currency-Api, ExchangeRate.host, Coinmarketcap, CryptoCompare and Coingecko.
JavaScript
249
star
17

currencyinfo

Self-hosted crypto and fiat currency rates service provider. Combines MOEX, Currency-Api, ExchangeRate.host, Coinmarketcap, CryptoCompare, and Coingecko.
TypeScript
146
star
18

adamant-android

Android native client for ADAMANT Messenger
Java
28
star
19

adamant-fcm-notification-service

FCM push notification service for ADAMANT
Java
3
star
20

adamant-bountybot

Carry out bounty campaigns & crypto airdrops, with automatic task verifications and payouts. Bounty bots work in ADAMANT Messenger chats directly.
JavaScript
3
star
21

adamant-pool

ADAMANT Forging pool with Web interface
JavaScript
2
star
22

adamant-bet

Anonymous and Blockchain-proved betting on crypto rates
JavaScript
2
star
23

adamant-tradebot-dex

Free market-making software on decentralized exchanges (DEX) for cryptocurrency projects. Makes trade volume, manages liquidity, watches a token price. [In development]
1
star
24

adamant-watchbot

Watches ADAMANT blockchain transactions, notifies about specific ones, recoups fees
JavaScript
1
star
25

adamant-docker

ADAMANT node for Docker
Shell
1
star
26

adamant-trader

Advanced open-source cryptocurrency tradebot
1
star
27

ipfs-node

IPFS decentralized file storage and transfers
1
star