use of co.krypt.krypton.pgp.PGPPublicKey in project krypton-android by kryptco.
the class MeStorage method loadWithUserID.
public Profile loadWithUserID(@Nullable UserID userID) {
synchronized (lock) {
String meJSON = preferences.getString("ME", null);
if (meJSON == null) {
Log.i(TAG, "no profile found");
return null;
}
Profile me = JSON.fromJson(meJSON, Profile.class);
if (me == null) {
Log.i(TAG, "no profile found");
return null;
}
try {
SSHKeyPairI kp = getOrLoadKeyPair(context);
if (kp != null) {
me.sshWirePublicKey = kp.publicKeySSHWireFormat();
if (userID != null) {
try {
List<UserID> userIDs = getUserIDs();
// keep USER_ID_LIMIT most recent UserIDs
if (userIDs.remove(userID)) {
userIDs.add(userID);
} else {
if (userIDs.size() >= USER_ID_LIMIT) {
userIDs.remove(0);
}
userIDs.add(userID);
PGPPublicKey pgpPublicKey = PGPManager.publicKeyWithIdentities(kp, userIDs);
me.pgpPublicKey = pgpPublicKey.serializedBytes();
if (userIDs.size() == USER_ID_LIMIT) {
// detect abuse of exporting PGP userIDs
Notifications.notifyPGPKeyExport(context, pgpPublicKey);
}
}
set(me, userIDs);
} catch (PGPException | IOException e) {
e.printStackTrace();
}
}
}
} catch (InvalidKeyException | IOException | CryptoException e) {
e.printStackTrace();
}
try {
me.teamCheckpoint = TeamDataProvider.getTeamCheckpoint(context).success;
} catch (Native.NotLinked notLinked) {
notLinked.printStackTrace();
}
return me;
}
}
use of co.krypt.krypton.pgp.PGPPublicKey in project krypton-android by kryptco.
the class PGPCodesignTest method dataSigning_succeeds.
@Test
public void dataSigning_succeeds() throws Exception {
final byte[] data = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
SSHKeyPairI kp1 = KeyManager.loadOrGenerateKeyPair(InstrumentationRegistry.getTargetContext(), KeyType.RSA, "test");
PGPPublicKey pubkey = new PGPPublicKey(kp1, Collections.singletonList(new UserID("Kevin King", "kevin@krypt.co")));
UnsignedBinaryDocument unsigned = new UnsignedBinaryDocument(data, kp1, HashAlgorithm.SHA512);
SignedSignatureAttributes sig = unsigned.sign(kp1.pgpSign(HashAlgorithm.SHA512, SignableUtils.signableBytes(unsigned)));
byte[] serializedSig = sig.serializedBytes();
SignedSignatureAttributes parsedSig = SignedSignatureAttributes.parse(new DataInputStream(new ByteArrayInputStream(serializedSig)));
Assert.assertTrue(parsedSig.attributes.attributes.hashAlgorithm == HashAlgorithm.SHA512);
Assert.assertTrue(parsedSig.attributes.attributes.pkAlgorithm == PublicKeyAlgorithm.RSA_SIGN_ONLY);
Assert.assertTrue(parsedSig.attributes.attributes.type == SignatureType.BINARY);
Assert.assertFalse(parsedSig.attributes.attributes.unhashedSubpackets.issuer.header.type.critical);
}
use of co.krypt.krypton.pgp.PGPPublicKey in project krypton-android by kryptco.
the class PGPublicKeySelfCertificationTest method keySigning_succeeds.
@Test
public void keySigning_succeeds() throws Exception {
for (KeyType keyType : new KeyType[] { KeyType.RSA, KeyType.Ed25519 }) {
SSHKeyPairI kp1 = KeyManager.loadOrGenerateKeyPair(InstrumentationRegistry.getTargetContext(), keyType, "test");
PGPPublicKey pubkey = new PGPPublicKey(kp1, Collections.singletonList(new UserID("Kevin King", "kevin@krypt.co")));
CertifiedPublicKey parsedPubkey = CertifiedPublicKey.parse(new DataInputStream(new ByteArrayInputStream(pubkey.serializedBytes())));
Assert.assertTrue(pubkey.signedIdentities.size() == parsedPubkey.identities.size());
Assert.assertFalse(pubkey.signedIdentities.get(0).signature.attributes.attributes.unhashedSubpackets.issuer.header.type.critical);
}
}
Aggregations