Add support for UUID-only delivery certificates. (SERVER-132)

This commit is contained in:
Jon Chambers
2020-08-19 11:24:23 -04:00
committed by Jon Chambers
parent a709a3bcc0
commit 2d75f59d33
4 changed files with 100 additions and 3 deletions

View File

@@ -28,14 +28,21 @@ public class CertificateGenerator {
this.serverCertificate = ServerCertificate.parseFrom(serverCertificate);
}
public byte[] createFor(Account account, Device device, boolean includeUuid) throws IOException, InvalidKeyException {
public byte[] createFor(Account account, Device device, boolean includeE164, boolean includeUuid) throws IOException, InvalidKeyException {
SenderCertificate.Certificate.Builder builder = SenderCertificate.Certificate.newBuilder()
.setSender(account.getNumber())
.setSenderDevice(Math.toIntExact(device.getId()))
.setExpires(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(expiresDays))
.setIdentityKey(ByteString.copyFrom(Base64.decode(account.getIdentityKey())))
.setSigner(serverCertificate);
if (!includeE164 && !includeUuid) {
throw new IllegalArgumentException("Certificates must include one of a sender phone number or UUID");
}
if (includeE164) {
builder.setSender(account.getNumber());
}
if (includeUuid) {
builder.setSenderUuid(account.getUuid().toString());
}