• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

signalapp/libsignal-service-java: A Java/Android library for communicating with ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

signalapp/libsignal-service-java

开源软件地址:

https://github.com/signalapp/libsignal-service-java

开源编程语言:

Java 100.0%

开源软件介绍:

signal-service-java

A Java library for communicating via Signal.

Implementing the Signal Protocol interfaces

The Signal encryption protocol is a stateful protocol, so libsignal-service users need to implement the storage interface SignalProtocolStore, which handles load/store of your key and session information to durable media.

Creating keys

IdentityKeyPair    identityKey        = KeyHelper.generateIdentityKeyPair();
List<PreKeyRecord> oneTimePreKeys     = KeyHelper.generatePreKeys(0, 100);
PreKeyRecord       lastResortKey      = KeyHelper.generateLastResortPreKey();
SignedPreKeyRecord signedPreKeyRecord = KeyHelper.generateSignedPreKey(identityKey, signedPreKeyId);

The above are then stored locally so that they're available for load via the SignalProtocolStore.

Registering

At install time, clients need to register with the Signal server.

private final String     URL         = "https://my.signal.server.com";
private final TrustStore TRUST_STORE = new MyTrustStoreImpl();
private final String     USERNAME    = "+14151231234";
private final String     PASSWORD    = generateRandomPassword();
private final String     USER_AGENT  = "[FILL_IN]";

SignalServiceAccountManager accountManager = new SignalServiceAccountManager(URL, TRUST_STORE,
                                                                             USERNAME, PASSWORD, USER_AGENT);

accountManager.requestSmsVerificationCode();
accountManager.verifyAccountWithCode(receivedSmsVerificationCode, generateRandomSignalingKey(),
                                     generateRandomInstallId(), false);
accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
accountManager.setPreKeys(identityKey.getPublicKey(), lastResortKey, signedPreKeyRecord, oneTimePreKeys);

Sending text messages

SignalServiceMessageSender messageSender = new SignalServiceMessageSender(URL, TRUST_STORE, USERNAME, PASSWORD,
                                                                          new MySignalProtocolStore(),
                                                                          USER_AGENT, Optional.absent());

messageSender.sendMessage(new SignalServiceAddress("+14159998888"),
                          SignalServiceDataMessage.newBuilder()
                                                  .withBody("Hello, world!")
                                                  .build());

Sending media messages

SignalServiceMessageSender messageSender = new SignalServiceMessageSender(URL, TRUST_STORE, USERNAME, PASSWORD,
                                                                          new MySignalProtocolStore(),
                                                                          USER_AGENT, Optional.absent());

File                    myAttachment     = new File("/path/to/my.attachment");
FileInputStream         attachmentStream = new FileInputStream(myAttachment);
SignalServiceAttachment attachment       = SignalServiceAttachment.newStreamBuilder()
                                                                  .withStream(attachmentStream)
                                                                  .withContentType("image/png")
                                                                  .withLength(myAttachment.length())
                                                                  .build();

messageSender.sendMessage(new SignalServiceAddress("+14159998888"),
                          SignalServiceDataMessage.newBuilder()
                                                  .withBody("An attachment!")
                                                  .withAttachment(attachment)
                                                  .build());

Receiving messages

SignalServiceMessageReceiver messageReceiver = new SignalServiceMessageReceiver(URL, TRUST_STORE, USERNAME,
                                                                                PASSWORD, mySignalingKey,
                                                                                USER_AGENT);
SignalServiceMessagePipe     messagePipe     = null;

try {
  messagePipe = messageReceiver.createMessagePipe();

  while (listeningForMessages) {
    SignalServiceEnvelope envelope = messagePipe.read(timeout, timeoutTimeUnit);
    SignalServiceCipher   cipher   = new SignalServiceCipher(new SignalServiceAddress(USERNAME),
                                                             new MySignalProtocolStore());
    SignalServiceContent  message  = cipher.decrypt(envelope);

    System.out.println("Received message: " + message.getDataMessage().get().getBody().get());
  }

} finally {
  if (messagePipe != null)
    messagePipe.shutdown();
}

Legal things

Cryptography Notice

This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See http://www.wassenaar.org/ for more information.

The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms. The form and manner of this distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code.

License

Copyright 2013-2016 Open Whisper Systems

Licensed under the AGPLv3: https://www.gnu.org/licenses/agpl-3.0.html




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap