-
Notifications
You must be signed in to change notification settings - Fork 14
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
91c4249
Added extension functions for KeyRingInfo and PGPKeyRing. Added PgpAr…
DenBond7 f7f76ee
Dropped Node.generateKey(). Refactored code.| #1068
DenBond7 92f2c01
Fixed generation 'KeyId'. Refactored code.| #1055
DenBond7 0558575
Modified PGPKeyRing.toNodeKeyDetails().| #1055
DenBond7 b393da9
Fixed a bug in PgpArmorUtils.| #1055
DenBond7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/request/node/GenerateKeyRequest.kt
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/response/node/GenerateKeyResult.kt
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
FlowCrypt/src/main/java/com/flowcrypt/email/extensions/KeyRingInfoExt.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
FlowCrypt/src/main/java/com/flowcrypt/email/extensions/PGPKeyRingExt.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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