• This repository has been archived on 05/Aug/2021
  • Stars
    star
    1,963
  • Rank 22,704 (Top 0.5 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created almost 8 years ago
  • Updated almost 3 years ago

Reviews

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

Repository Details

This library is no longer maintained. libsignal-protocol-javascript was an implementation of the Signal Protocol, written in JavaScript. It has been replaced by libsignal-client’s typesafe TypeScript API.

Deprecation Warning: It is recommended that the TypeScript interface of libsignal-client be used for all new applications. This library is no longer used by us or maintained.

libsignal-protocol-javascript

Build Status

Signal Protocol implementation for the browser based on libsignal-protocol-java.

/dist       # Distributables
/build      # Intermediate build files
/src        # JS source files
/native     # C source files for curve25519
/protos     # Protobuf definitions
/test       # Tests

Overview

A ratcheting forward secrecy protocol that works in synchronous and asynchronous messaging environments.

PreKeys

This protocol uses a concept called 'PreKeys'. A PreKey is an ECPublicKey and an associated unique ID which are stored together by a server. PreKeys can also be signed.

At install time, clients generate a single signed PreKey, as well as a large list of unsigned PreKeys, and transmit all of them to the server.

Sessions

Signal Protocol is session-oriented. Clients establish a "session," which is then used for all subsequent encrypt/decrypt operations. There is no need to ever tear down a session once one has been established.

Sessions are established in one of two ways:

  1. PreKeyBundles. A client that wishes to send a message to a recipient can establish a session by retrieving a PreKeyBundle for that recipient from the server.
  2. PreKeySignalMessages. A client can receive a PreKeySignalMessage from a recipient and use it to establish a session.

State

An established session encapsulates a lot of state between two clients. That state is maintained in durable records which need to be kept for the life of the session.

State is kept in the following places:

  • Identity State. Clients will need to maintain the state of their own identity key pair, as well as identity keys received from other clients.
  • PreKey State. Clients will need to maintain the state of their generated PreKeys.
  • Signed PreKey States. Clients will need to maintain the state of their signed PreKeys.
  • Session State. Clients will need to maintain the state of the sessions they have established.

Requirements

This implementation currently depends on the presence of the following types/interfaces, which are available in most modern browsers.

Usage

Include dist/libsignal-protocol.js in your webpage.

Install time

At install time, a libsignal client needs to generate its identity keys, registration id, and prekeys.

var KeyHelper = libsignal.KeyHelper;

var registrationId = KeyHelper.generateRegistrationId();
// Store registrationId somewhere durable and safe.

KeyHelper.generateIdentityKeyPair().then(function(identityKeyPair) {
    // keyPair -> { pubKey: ArrayBuffer, privKey: ArrayBuffer }
    // Store identityKeyPair somewhere durable and safe.
});

KeyHelper.generatePreKey(keyId).then(function(preKey) {
    store.storePreKey(preKey.keyId, preKey.keyPair);
});

KeyHelper.generateSignedPreKey(identityKeyPair, keyId).then(function(signedPreKey) {
    store.storeSignedPreKey(signedPreKey.keyId, signedPreKey.keyPair);
});

// Register preKeys and signedPreKey with the server

Building a session

A libsignal client needs to implement a storage interface that will manage loading and storing of identity, prekeys, signed prekeys, and session state. See test/InMemorySignalProtocolStore.js for an example.

Once this is implemented, building a session is fairly straightforward:

var store   = new MySignalProtocolStore();
var address = new libsignal.SignalProtocolAddress(recipientId, deviceId);

// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
var sessionBuilder = new libsignal.SessionBuilder(store, address);

// Process a prekey fetched from the server. Returns a promise that resolves
// once a session is created and saved in the store, or rejects if the
// identityKey differs from a previously seen identity for this address.
var promise = sessionBuilder.processPreKey({
    registrationId: <Number>,
    identityKey: <ArrayBuffer>,
    signedPreKey: {
        keyId     : <Number>,
        publicKey : <ArrayBuffer>,
        signature : <ArrayBuffer>
    },
    preKey: {
        keyId     : <Number>,
        publicKey : <ArrayBuffer>
    }
});

promise.then(function onsuccess() {
  // encrypt messages
});

promise.catch(function onerror(error) {
  // handle identity key conflict
});

Encrypting

Once you have a session established with an address, you can encrypt messages using SessionCipher.

var plaintext = "Hello world";
var sessionCipher = new libsignal.SessionCipher(store, address);
sessionCipher.encrypt(plaintext).then(function(ciphertext) {
    // ciphertext -> { type: <Number>, body: <string> }
    handle(ciphertext.type, ciphertext.body);
});

Decrypting

Ciphertexts come in two flavors: WhisperMessage and PreKeyWhisperMessage.

var address = new SignalProtocolAddress(recipientId, deviceId);
var sessionCipher = new SessionCipher(store, address);

// Decrypt a PreKeyWhisperMessage by first establishing a new session.
// Returns a promise that resolves when the message is decrypted or
// rejects if the identityKey differs from a previously seen identity for this
// address.
sessionCipher.decryptPreKeyWhisperMessage(ciphertext).then(function(plaintext) {
    // handle plaintext ArrayBuffer
}).catch(function(error) {
    // handle identity key conflict
});

// Decrypt a normal message using an existing session
var sessionCipher = new SessionCipher(store, address);
sessionCipher.decryptWhisperMessage(ciphertext).then(function(plaintext) {
    // handle plaintext ArrayBuffer
});

Building

To compile curve25519 from C source files in /native, install emscripten.

grunt compile

License

Copyright 2015-2018 Open Whisper Systems

Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html

More Repositories

1

Signal-Android

A private messenger for Android.
Java
24,766
star
2

Signal-Desktop

A private messenger for Windows, macOS, and Linux.
TypeScript
13,934
star
3

Signal-iOS

A private messenger for iOS.
Swift
10,405
star
4

Signal-Server

Server supporting the Signal Private Messenger applications on Android, Desktop, and iOS
Java
8,781
star
5

libsignal

Home to the Signal Protocol as well as other cryptographic primitives which make Signal possible.
Rust
2,820
star
6

libsignal-protocol-java

Java
1,814
star
7

libsignal-protocol-c

C
1,406
star
8

BitHub

BTC + BitHub = An experiment in funding privacy OSS.
Java
999
star
9

libsignal-service-java

A Java/Android library for communicating with the Signal messaging service.
Java
574
star
10

Signal-TLS-Proxy

Dockerfile
552
star
11

ringrtc

Rust
522
star
12

Signal-Calling-Service

Forwards media from 1 group call device to N group call devices.
Rust
409
star
13

Flock

Private contact and calendar sync for Android.
Java
359
star
14

ContactDiscoveryService

C
277
star
15

SecureValueRecovery

Rust
276
star
16

gradle-witness

A gradle plugin that enables static verification for remote dependencies.
Groovy
228
star
17

curve25519-java

Pure Java and JNI backed Curve25519 implementation.
C
225
star
18

SignalProtocolKit

This library is no longer maintained. SignalProtocolKit was an implementation of the Signal Protocol, written in Objective-C. It has been replaced by libsignal-client’s type safe Swift API.
Objective-C
214
star
19

webrtc

C++
127
star
20

PushServer

A microservice for communicating with push gateways.
Java
115
star
21

WhisperYAFFS

Encrypted Filesystem Support For YAFFS2
C
103
star
22

jobmanager

Android library for executing tasks.
Java
103
star
23

WebSocket-Resources

A Dropwizard library that lets you use Jersey-style Resources over WebSockets
Java
91
star
24

better-sqlite3

C++
68
star
25

SignalServiceKit

SignalServiceKit has moved to Signal-iOS. See README.md for details.
Objective-C
68
star
26

libwebrtc-android

Android WebRTC Packages
Java
58
star
27

Signal-Pods

Pods dependency tracker for Signal-iOS
C
54
star
28

signal-ringrtc-node

TypeScript
48
star
29

gcm-sender-async

Asynchronous Google Cloud Messaging (GCM) Library
Java
48
star
30

zkgroup

41
star
31

libsignal-protocol-rust

Rust
38
star
32

Signal-Design

A place to archive design assets used by Signal.
35
star
33

curve25519-dalek

Rust
34
star
34

Argon2

Java
34
star
35

signal-webrtc-ios

Python
33
star
36

SignalCoreKit

Swift
31
star
37

storage-service

Java
28
star
38

libpastelog

Java
27
star
39

maven

26
star
40

Signal-FTS5-Extension

A FTS5 extension for signal_tokenizer.
Rust
26
star
41

ContactDiscoveryService-Icelake

C
25
star
42

SecureValueRecovery2

C++
23
star
43

dropwizard-simpleauth

Dropwizard library for simple @Auth annotations that support multiple types
Java
22
star
44

CLAServer

GitHub Integration for managing CLA signatures
Java
22
star
45

Mock-Signal-Server

TypeScript
21
star
46

mio

Rust
20
star
47

AES-GCM-Provider

A BoringSSL-backed AES-GCM provider for Android with support for "incremental" encryption/decryption
Java
19
star
48

registration-service

Registration Service for Signal
Java
17
star
49

libaxolotl-j2me

Axolotl J2ME
Java
17
star
50

signal-webrtc-ios-artifacts

Objective-C
17
star
51

tus-server

An implementation of the TUS server protocol for resumable uploads
TypeScript
15
star
52

SQLCipherVsSharedData

Demo Project to demonstrate a bug in SQLCipher
Objective-C
15
star
53

Signal-Art-Creator

Sticker Pack Creator Web App
TypeScript
15
star
54

dropwizard-wavefront

Dropwizard Metrics Reporter For Wavefront
Java
14
star
55

SignalMetadataKit

Swift
13
star
56

sgx_common

Rust
13
star
57

Signal-Carthage

Objective-C
12
star
58

emoji-search-index

Static assets used for to generate a search index for emoji within Signal.
11
star
59

libsignal-client-node

11
star
60

redis-dispatch

Java
11
star
61

libsignal-metadata-java

Java
10
star
62

libmobilecoin-ios-artifacts

Swift
10
star
63

signal-zkgroup-node

TypeScript
9
star
64

poksho

9
star
65

AccountStream

Java
7
star
66

jekyll-simple-i18n

Ruby
7
star
67

s3-upload-maven-plugin

Maven plugin to upload files to s3
Java
6
star
68

mp4san

A Rust MP4 format sanitizer
Rust
6
star
69

sqlcipher

C
5
star
70

libsignal-ffi

Rust
4
star
71

HsmEnclave

HSM-backed remote-attestable enclave.
C
4
star
72

signal-zkgroup-swift

Swift
4
star
73

sqlcipher-android

A light fork of https://github.com/sqlcipher/sqlcipher-android
C
4
star
74

partial-default

Provides PartialDefault, a Rust trait similar to Default but with fewer guarantees
Rust
2
star
75

libsignal-protocol-swift

Swift
2
star
76

storage-manager

Manage objects inside a cdn
TypeScript
1
star