UNPKG

thali

Version:
210 lines (176 loc) 13.2 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: thaliNotificationBeacons.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: thaliNotificationBeacons.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>"use strict"; /** @module thaliNotificationBeacons */ /* Matt: Please make sure to see if you can find Srikanth's code in Node and of course you can look at the Java source code and tests linked to in the spec, the latest version of which is at https://github.com/thaliproject/thali/blob/yaronyg-patch-4/presenceprotocolforop portunisticsynching.md */ /** * This function will generate a buffer containing the notification preamble and * beacons for the given set of public keys using the supplied private key and * set to the specified seconds until expiration. * @param {string[]} publicKeysToNotify - An array of strings holding base64 url * safe encoded ECDH public keys * @param {ECDH} ecdhForLocalDevice - A Crypto.ECDH object initialized with the * local device's public and private keys * @param {number} secondsUntilExpiration - The number of seconds into the * future after which the beacons should expire. * @returns {Buffer} - A buffer containing the serialized preamble and beacons */ module.exports.generatePreambleAndBeacons = function (publicKeysToNotify, ecdhForLocalDevice, secondsUntilExpiration) { // This implements the generateBeacons function from the specs. I don't take // the IV or Ke as arguments because those can be generated inside the // function. Note that you will need to use crypto.ECDH to implement this // functionality which was introduced in Node 0.12 and isn't in JXcore yet. So // for now please just develop using Node 0.12 or Node 4 until we get this // back ported to JXcore. The complication with using Node 0.12 is that it // won't have the custom extension we need to crypto that JXcore provided to // support HKDF. See // http://jxcore.com/docs/crypto.html#cryptogeneratehkdfbytestogenerate-public // ke y-salt-digestbuffer The work around is to use // https://www.npmjs.com/package/node-hkdf but we *MUST* remove this quickly // because it doesn't have a published license. return new Buffer(); }; /** * Generates a single beacon using the specified values. * @param {string} publicKey - This is a base64 url safe encoded public key we * need to create a beacon for * @param {ECDH} ecdhWithPrivateKey - A Crypto.ECDH object initialized with the * local device's public and private keys * @param {Buffer} IV - The IV to use for this beacon (we use the same IV for * all beacons) * @param {ECDH} Ke - A Crypto.ECDH object initialized with the public and * private ephemeral key * @param {Buffer} expirationValue - The calculated expirationValue used the * pre-amble that pairs with this beacon * @returns {Buffer} - A buffer containing the beacon */ function generateBeacon(publicKey, ecdhWithPrivateKey, IV, Ke, expirationValue) { return new Buffer(); } /** * This callback is used to lookup if the public key hash retrieved from a * notification beacon belongs to a peer that the local peer wishes to talk to. * If not the callback will return null. If so then the callback will return the * full public key for the remote peer. In other words, there is an explicit * assumption that the caller has an address book mapping hashes of public keys * with the full public keys. The hashes are in the beacon and this function is * used to retrieve the full public key so that the beacon validation process * can complete. * @callback addressBookCallback * @param {Buffer} unencryptedKeyId - This is a Buffer containing the * unencryptedKeId. * @returns {string} - The base64 url safe encoded public key associated with * the unecryptedKeyId or null if the remote peer is not one the local peer * recognizes or wishes to communicate with. */ /** * Response object describing a successfully parsed beacon. * * The definition of pskIdentifyField and psk are as given * [here](https://github.com/thaliproject/thali/blob/gh-pages/pages/documentation/PresenceProtocolForOpportunisticSynching.md#processing-the-pre-amble-and-beacons). * * @public * @constructor * @param {buffer} keyId The buffer contains the HKey as defined * [here](https://github.com/thaliproject/thali/blob/gh-pages/pages/documentatio * n/PresenceProtocolForOpportunisticSynching.md#processing-the-pre-amble-and-be * acons). * @param {string} pskIdentifyField This is the value to put in the PSK identity * field of the ClientKeyExchange message when establishing a TLS connection * using PSK. This value is generated * @param {buffer} psk This is the calculated pre-shared key that will be needed * to establish a TLS PSK connection. */ function ParseBeaconsResponse(keyId, pskIdentifyField, psk) { this.keyId = keyId; this.pskIdentifyField = pskIdentifyField; this.psk = psk; } /** * @private * @type {buffer} */ ParseBeaconsResponse.prototype.keyId = null; ParseBeaconsResponse.prototype.getKeyId = function () { return this.keyId; }; /** * @private * @type {string} */ ParseBeaconsResponse.prototype.pskIdentifyField = null; ParseBeaconsResponse.prototype.getPskIdentifyField = function () { return this.pskIdentifyField; }; /** * @private * @type {buffer} */ ParseBeaconsResponse.prototype.psk = null; ParseBeaconsResponse.prototype.getPsk = function () { return this.psk; }; module.exports.ParseBeaconsResponse = ParseBeaconsResponse; /** * * @public * @param {Buffer} beaconStreamWithPreAmble - A buffer stream containing the * preamble and beacons * @param {Crypto.ECDH} ecdhForLocalDevice - A Crypto.ECDH object initialized * with the local device's public and private keys * @param {addressBookCallback} addressBookCallback - A callback used by the * function to determine if the identified remote peer's public key hash * represents a remote peer the local peer wishes to communicate with. * @returns {module:thaliNotificationBeacons~ParseBeaconsResponse} - Null if * none of the beacons could be validated as being targeted at the local peer or * if the beacon came from a remote peer the local peer does not wish to * communicate with. Otherwise a {@type ParseBeaconsResponse}. */ module.exports.parseBeacons = function (beaconStreamWithPreAmble, ecdhForLocalDevice, addressBookCallback) { // Unlike the pseudo code this function assumes it will be passed the entire // preamble and beacon stream. Therefore the PubKe and the expiration can be // parsed out of the beaconStreamWithPreAmble as defined in the spec. return null; }; </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-TCPServersManager.html">TCPServersManager</a></li><li><a href="module-thaliMobile.html">thaliMobile</a></li><li><a href="module-thaliMobileNative.html">thaliMobileNative</a></li><li><a href="module-thaliMobileNativeWrapper.html">thaliMobileNativeWrapper</a></li><li><a href="module-thaliNotificationAction.html">thaliNotificationAction</a></li><li><a href="module-thaliNotificationBeacons.html">thaliNotificationBeacons</a></li><li><a href="module-thaliNotificationClient.html">thaliNotificationClient</a></li><li><a href="module-thaliNotificationServer.html">thaliNotificationServer</a></li><li><a href="module-thaliPeerAction.html">thaliPeerAction</a></li><li><a href="module-thaliPeerDictionary.html">thaliPeerDictionary</a></li><li><a href="module-thaliPeerPoolInterface.html">thaliPeerPoolInterface</a></li><li><a href="module-ThaliWifiInfrastructure.html">ThaliWifiInfrastructure</a></li><li><a href="module-WifiBasedNativeMock.html">WifiBasedNativeMock</a></li></ul><h3>Externals</h3><ul><li><a href="external-_Mobile(_connect_)_.html">Mobile('connect')</a></li><li><a href="external-_Mobile(_discoveryAdvertisingStateUpdateNonTCP_)_.html">Mobile('discoveryAdvertisingStateUpdateNonTCP')</a></li><li><a href="external-_Mobile(_incomingConnectionToPortNumberFailed_)_.html">Mobile('incomingConnectionToPortNumberFailed')</a></li><li><a href="external-_Mobile(_killConnections_)_.html">Mobile('killConnections')</a></li><li><a href="external-_Mobile(_networkChanged_)_.html">Mobile('networkChanged')</a></li><li><a href="external-_Mobile(_peerAvailabilityChanged_)_.html">Mobile('peerAvailabilityChanged')</a></li><li><a href="external-_Mobile(_startListeningForAdvertisements_)_.html">Mobile('startListeningForAdvertisements')</a></li><li><a href="external-_Mobile(_startUpdateAdvertisingAndListening_)_.html">Mobile('startUpdateAdvertisingAndListening')</a></li><li><a href="external-_Mobile(_stopAdvertisingAndListening_)_.html">Mobile('stopAdvertisingAndListening')</a></li><li><a href="external-_Mobile(_stopListeningForAdvertisements_)_.html">Mobile('stopListeningForAdvertisements')</a></li></ul><h3>Classes</h3><ul><li><a href="ConnectionTable.html">ConnectionTable</a></li><li><a href="module-TCPServersManager-TCPServersManager.html">TCPServersManager</a></li><li><a href="module-thaliNotificationAction-NotificationAction.html">NotificationAction</a></li><li><a href="module-thaliNotificationBeacons-ParseBeaconsResponse.html">ParseBeaconsResponse</a></li><li><a href="module-thaliNotificationClient-ThaliNotificationClient.html">ThaliNotificationClient</a></li><li><a href="module-thaliNotificationServer-ThaliNotificationServer.html">ThaliNotificationServer</a></li><li><a href="module-thaliPeerAction-PeerAction.html">PeerAction</a></li><li><a href="module-thaliPeerDictionary-NotificationPeerDictionaryEntry.html">NotificationPeerDictionaryEntry</a></li><li><a href="module-thaliPeerDictionary-PeerConnectionInformation.html">PeerConnectionInformation</a></li><li><a href="module-thaliPeerDictionary-PeerDictionary.html">PeerDictionary</a></li><li><a href="module-thaliPeerPoolInterface-ThaliPeerPoolInterface.html">ThaliPeerPoolInterface</a></li><li><a href="module-ThaliWifiInfrastructure-ThaliWifiInfrastructure.html">ThaliWifiInfrastructure</a></li><li><a href="module-WifiBasedNativeMock-MobileCallInstance.html">MobileCallInstance</a></li><li><a href="module-WifiBasedNativeMock-WifiBasedNativeMock.html">WifiBasedNativeMock</a></li></ul><h3>Events</h3><ul><li><a href="module-thaliMobileNativeWrapper.html#~event:discoveryAdvertisingStateUpdateNonTCPEvent">discoveryAdvertisingStateUpdateNonTCPEvent</a></li><li><a href="module-ThaliWifiInfrastructure.html#~event:discoveryAdvertisingStateUpdateWifiEvent">discoveryAdvertisingStateUpdateWifiEvent</a></li><li><a href="module-TCPServersManager.html#~event:failedConnection">failedConnection</a></li><li><a href="module-thaliMobileNativeWrapper.html#~event:incomingConnectionToPortNumberFailed">incomingConnectionToPortNumberFailed</a></li><li><a href="module-thaliMobileNativeWrapper.html#~event:networkChangedNonTCP">networkChangedNonTCP</a></li><li><a href="module-ThaliWifiInfrastructure.html#~event:networkChangedWifi">networkChangedWifi</a></li><li><a href="module-thaliMobileNativeWrapper.html#~event:nonTCPPeerAvailabilityChangedEvent">nonTCPPeerAvailabilityChangedEvent</a></li><li><a href="module-TCPServersManager.html#~event:routerPortConnectionFailed">routerPortConnectionFailed</a></li><li><a href="module-ThaliWifiInfrastructure.html#~event:wifiPeerAvailabilityChanged">wifiPeerAvailabilityChanged</a></li><li><a href="module-thaliMobile.html#.event:event:discoveryAdvertisingStateUpdate">discoveryAdvertisingStateUpdate</a></li><li><a href="module-thaliMobile.html#.event:event:networkChanged">networkChanged</a></li><li><a href="module-thaliMobile.html#.event:event:peerAvailabilityChanged">peerAvailabilityChanged</a></li><li><a href="module-thaliNotificationAction-NotificationAction.html#.event:event:Resolved">Resolved</a></li><li><a href="module-thaliNotificationClient.html#.event:event:peerAdvertisesDataForUs">peerAdvertisesDataForUs</a></li></ul><h3>Global</h3><ul><li><a href="global.html#getPKCS12Content">getPKCS12Content</a></li><li><a href="global.html#getPublicKeyHash">getPublicKeyHash</a></li><li><a href="global.html#stopThaliReplicationManager">stopThaliReplicationManager</a></li><li><a href="global.html#ThaliEmitter">ThaliEmitter</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Jan 18 2016 11:19:31 GMT+0200 (EET) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>