Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 15
Issue 1055 gen keys via pgpainless#1085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
91c4249f7f76ee92f2c010558575b393da9File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com | ||
| * Contributors: DenBond7 | ||
| */ | ||
| package com.flowcrypt.email.extensions | ||
| import org.pgpainless.algorithm.SymmetricKeyAlgorithm | ||
| import org.pgpainless.key.info.KeyRingInfo | ||
| /** | ||
| * @author Denis Bondarenko | ||
| * Date: 3/11/21 | ||
| * Time: 10:33 AM | ||
| * E-mail: DenBond7@gmail.com | ||
| */ | ||
| /** | ||
| * Return true when every secret key on the key ring is encrypted. | ||
| * If there is at least one unencrypted secret key on the ring, return false. | ||
| * If the ring is a [PGPPublicKeyRing], return false. | ||
| * | ||
| * @return true if all secret keys are encrypted. | ||
| */ | ||
| fun KeyRingInfo.isFullyEncrypted(): Boolean { | ||
| if (isSecretKey) { | ||
| for (secretKey in secretKeys) { | ||
| if (secretKey.keyEncryptionAlgorithm == SymmetricKeyAlgorithm.NULL.algorithmId) { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } else return false | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com | ||
| * Contributors: DenBond7 | ||
| */ | ||
| package com.flowcrypt.email.extensions | ||
| import com.flowcrypt.email.api.retrofit.response.model.node.Algo | ||
| import com.flowcrypt.email.api.retrofit.response.model.node.KeyId | ||
| import com.flowcrypt.email.api.retrofit.response.model.node.NodeKeyDetails | ||
| import com.flowcrypt.email.security.pgp.PgpArmorUtils | ||
| import org.bouncycastle.openpgp.PGPKeyRing | ||
| import org.bouncycastle.openpgp.PGPSecretKeyRing | ||
| import org.pgpainless.algorithm.PublicKeyAlgorithm | ||
| import org.pgpainless.key.OpenPgpV4Fingerprint | ||
| import org.pgpainless.key.generation.type.eddsa.EdDSACurve | ||
| import org.pgpainless.key.info.KeyInfo | ||
| import org.pgpainless.key.info.KeyRingInfo | ||
| import org.pgpainless.key.util.KeyRingUtils | ||
| import java.util.concurrent.TimeUnit | ||
| /** | ||
| * @author Denis Bondarenko | ||
| * Date: 3/11/21 | ||
| * Time: 10:08 AM | ||
| * E-mail: DenBond7@gmail.com | ||
| */ | ||
| fun PGPKeyRing.toNodeKeyDetails(): NodeKeyDetails { | ||
| val keyRingInfo = KeyRingInfo(this) | ||
| val algo = Algo( | ||
| algorithm = keyRingInfo.algorithm.name, | ||
| algorithmId = keyRingInfo.algorithm.algorithmId, | ||
| bits = if (keyRingInfo.publicKey.bitStrength != -1) keyRingInfo.publicKey.bitStrength else 0, | ||
| curve = when (keyRingInfo.algorithm) { | ||
| PublicKeyAlgorithm.ECDSA, PublicKeyAlgorithm.ECDH -> KeyInfo.getCurveName(publicKey) | ||
| PublicKeyAlgorithm.EDDSA -> EdDSACurve._Ed25519.getName() // for EDDSA KeyInfo.getCurveName(publicKey) return null | ||
| else -> null | ||
| } | ||
| ) | ||
| val ids = publicKeys.iterator().asSequence().toList() | ||
| .map { | ||
| val fingerprint = OpenPgpV4Fingerprint(it) | ||
| KeyId( | ||
| fingerprint = fingerprint.toString(), | ||
| longId = fingerprint.takeLast(16).toString(), | ||
| shortId = fingerprint.takeLast(8).toString(), | ||
| keywords = ""//skipped as deprecated | ||
| ) | ||
| } | ||
| val privateKey = if (keyRingInfo.isSecretKey) PgpArmorUtils.toAsciiArmoredString(this) else null | ||
| val publicKey = if (keyRingInfo.isSecretKey) { | ||
| PgpArmorUtils.toAsciiArmoredString(KeyRingUtils.publicKeyRingFrom(this as PGPSecretKeyRing?)) | ||
| } else { | ||
| PgpArmorUtils.toAsciiArmoredString(this) | ||
| } | ||
| return NodeKeyDetails( | ||
| isFullyDecrypted = keyRingInfo.isFullyDecrypted, | ||
| isFullyEncrypted = keyRingInfo.isFullyEncrypted(), | ||
| privateKey = privateKey, | ||
| publicKey = publicKey, | ||
| users = keyRingInfo.userIds, | ||
| ids = ids, | ||
| created = TimeUnit.SECONDS.convert(keyRingInfo.creationDate.time, TimeUnit.MILLISECONDS), | ||
| lastModified = TimeUnit.SECONDS.convert(keyRingInfo.lastModified.time, TimeUnit.MILLISECONDS), | ||
| expiration = TimeUnit.SECONDS.convert(keyRingInfo.expirationDate?.time | ||
| ?: 0, TimeUnit.MILLISECONDS), | ||
| algo = algo, | ||
| passphrase = null, | ||
| errorMsg = null) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to cross check this
isFullyEncrypted- for one thing there is a dummy gnu S2K requiring special treatment, second there could be some null-like encryption method like plain. (sometimes the spec is messy). That will be for another PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref pgpainless/pgpainless#99