Changeset 30829 in osm for applications/editors/josm/plugins/trustosm/src/org
- Timestamp:
- 2014-11-29T20:52:09+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/TrustGPG.java
r30744 r30829 19 19 import java.security.NoSuchAlgorithmException; 20 20 import java.security.NoSuchProviderException; 21 import java.security.Provider; 21 22 import java.security.SecureRandom; 22 23 import java.security.Security; … … 47 48 import javax.swing.SpringLayout; 48 49 50 import org.bouncycastle.bcpg.HashAlgorithmTags; 49 51 import org.bouncycastle.bcpg.sig.NotationData; 50 52 import org.bouncycastle.jce.provider.BouncyCastleProvider; … … 65 67 import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; 66 68 import org.bouncycastle.openpgp.PGPUtil; 69 import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; 70 import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor; 71 import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder; 72 import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider; 73 import org.bouncycastle.openpgp.operator.PGPDigestCalculator; 74 import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider; 75 import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; 76 import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider; 77 import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; 78 import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair; 79 import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; 80 import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; 67 81 import org.bouncycastle.util.encoders.Hex; 68 82 import org.openstreetmap.josm.Main; … … 534 548 } 535 549 536 PGPPrivateKey pgpPrivKey = pgpSecKey.extractPrivateKey(password, "BC"); 537 PGPSignatureGenerator sGen = new PGPSignatureGenerator(pgpSecKey.getPublicKey().getAlgorithm(), digest, "BC"); 538 sGen.initSign(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey); 550 Provider provider = Security.getProvider("BC"); 551 PGPDigestCalculatorProvider digestCalculatorProvider = new JcaPGPDigestCalculatorProviderBuilder().setProvider(provider).build(); 552 PBESecretKeyDecryptor secretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder(digestCalculatorProvider).setProvider(provider).build(password); 553 PGPPrivateKey pgpPrivKey = pgpSecKey.extractPrivateKey(secretKeyDecryptor); 554 int keyAlgorithm = pgpSecKey.getPublicKey().getAlgorithm(); 555 PGPContentSignerBuilder contentSignerBuilder = new JcaPGPContentSignerBuilder(keyAlgorithm, digest).setProvider(provider).setDigestProvider(provider); 556 PGPSignatureGenerator sGen = new PGPSignatureGenerator(contentSignerBuilder); 557 sGen.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey); 539 558 540 559 Iterator<?> it = pgpSecKey.getPublicKey().getUserIDs(); … … 575 594 }*/ 576 595 try { 577 sig.initVerify(pgpPub.getPublicKey(sig.getKeyID()), "BC"); 596 Provider provider = Security.getProvider("BC"); 597 PGPContentVerifierBuilderProvider contentVerifierBuilderProvider = new JcaPGPContentVerifierBuilderProvider().setProvider(provider); 598 sig.init(contentVerifierBuilderProvider, pgpPub.getPublicKey(sig.getKeyID())); 578 599 sig.update(sigtext.getBytes(Charset.forName("UTF-8"))); 579 600 return sig.verify(); … … 812 833 813 834 Date now = new Date(); 814 PGPKeyPair pgpKp = new PGPKeyPair(al, kp, now); 835 PGPKeyPair pgpKp = new JcaPGPKeyPair(al, kp, now); 815 836 816 837 getPasswordfromUser(); … … 825 846 } 826 847 827 PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, pgpKp, 828 userId.getText(), protAl[protectBox.getSelectedIndex()], password, true, subPck, null, new SecureRandom(), "BC"); 848 Provider provider = Security.getProvider("BC"); 849 int encAlgorithm = protAl[protectBox.getSelectedIndex()]; 850 PGPDigestCalculator checksumCalculator = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1); 851 PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder(pgpKp.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1); 852 PBESecretKeyEncryptor encryptor = new JcePBESecretKeyEncryptorBuilder(encAlgorithm).setProvider(provider). 853 setSecureRandom(new SecureRandom()).build(password); 854 855 PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, pgpKp, userId.getText(), 856 checksumCalculator, subPck, null, signerBuilder, encryptor); 829 857 830 858 if (pgpPub == null) {
Note:
See TracChangeset
for help on using the changeset viewer.