Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 8847 invoked from network); 6 Dec 2005 23:27:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Dec 2005 23:27:51 -0000 Received: (qmail 6164 invoked by uid 500); 6 Dec 2005 23:27:48 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 5833 invoked by uid 500); 6 Dec 2005 23:27:46 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 5822 invoked by uid 500); 6 Dec 2005 23:27:46 -0000 Received: (qmail 5819 invoked by uid 99); 6 Dec 2005 23:27:46 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Dec 2005 15:27:46 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 06 Dec 2005 15:27:44 -0800 Received: (qmail 8569 invoked by uid 65534); 6 Dec 2005 23:27:23 -0000 Message-ID: <20051206232723.8567.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r354611 - in /jakarta/commons/sandbox/openpgp/trunk: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/commons/ src/main/java/org/apache/commons/openpgp/ src/test/ src/test/java/ src/test... Date: Tue, 06 Dec 2005 23:26:52 -0000 To: commons-cvs@jakarta.apache.org From: brett@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: brett Date: Tue Dec 6 15:00:39 2005 New Revision: 354611 URL: http://svn.apache.org/viewcvs?rev=354611&view=rev Log: first cut of the openpgp component Added: jakarta/commons/sandbox/openpgp/trunk/pom.xml (with props) jakarta/commons/sandbox/openpgp/trunk/src/ jakarta/commons/sandbox/openpgp/trunk/src/main/ jakarta/commons/sandbox/openpgp/trunk/src/main/java/ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignatureVerifier.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSigner.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/KeyRing.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpException.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureUpdater.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureVerifier.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSigner.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/SignatureStatus.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/UnknownKeyException.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/test/ jakarta/commons/sandbox/openpgp/trunk/src/test/java/ jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/ jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/ jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/commons/ jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/commons/openpgp/ jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignerTest.java (with props) jakarta/commons/sandbox/openpgp/trunk/src/test/resources/ jakarta/commons/sandbox/openpgp/trunk/src/test/resources/pubring.gpg (with props) jakarta/commons/sandbox/openpgp/trunk/src/test/resources/secring.gpg (with props) jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-input.txt (with props) jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-signature.asc Modified: jakarta/commons/sandbox/openpgp/trunk/ (props changed) Propchange: jakarta/commons/sandbox/openpgp/trunk/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Dec 6 15:00:39 2005 @@ -0,0 +1,4 @@ +*.iml +*.ipr +*.iws +target Added: jakarta/commons/sandbox/openpgp/trunk/pom.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/pom.xml?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/pom.xml (added) +++ jakarta/commons/sandbox/openpgp/trunk/pom.xml Tue Dec 6 15:00:39 2005 @@ -0,0 +1,139 @@ + + 4.0.0 + org.apache.commons + commons-openpgp + 1.0-SNAPSHOT + Commons OpenPGP + http://jakarta.apache.org/commons/sandbox/openpgp/ + + continuum + + + + +
brett@apache.org
+
+
+
+
+ + + org.bouncycastle + bcpg + 130 + + + junit + junit + 3.8.1 + test + + + commons-io + commons-io + 1.0 + test + + + + + brett + Brett Porter + brett AT apache DOT org + Apache + +10 + + + + scm:svn:http://svn.apache.org/repos/asf/jakarta/commons/sandbox/openpgp/trunk + + scm:svn:https://svn.apache.org/repos/asf/jakarta/commons/sandbox/openpgp/trunk + http://svn.apache.org/repos/asf/jakarta/commons/sandbox/openpgp/trunk + + + + The Apache Software Foundation + http://jakarta.apache.org + + + + The Apache Software License, Version 2.0 + /LICENSE.txt + repo + + + + + Commons Dev List + commons-dev-subscribe@jakarta.apache.org + commons-dev-unsubscribe@jakarta.apache.org + commons-dev@jakarta.apache.org + http://mail-archives.apache.org/mod_mbox/jakarta-commons-dev + + + Commons User List + commons-user-subscribe@jakarta.apache.org + commons-user-unsubscribe@jakarta.apache.org + commons-user@jakarta.apache.org + http://mail-archives.apache.org/mod_mbox/jakarta-commons-user + + + + + + + apache.snapshots + Apache Snapshot Repository + scp://minotaur.apache.org/www/cvs.apache.org/maven-snapshot-repository + + + website + Apache Website + scp://minotaur.apache.org/www/jakarta.apache.org/commons/sandbox/exec/ + + + + bugzilla + http://issues.apache.org/bugzilla/ + + + + + + maven-compiler-plugin + + 1.3 + 1.3 + + + + maven-idea-plugin + + 1.3 + + + + + + + + + org.apache.maven.plugins + maven-clover-plugin + + + threaded + 100 + + + + +
+ Propchange: jakarta/commons/sandbox/openpgp/trunk/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/pom.xml ------------------------------------------------------------------------------ svn:executable = * Propchange: jakarta/commons/sandbox/openpgp/trunk/pom.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,123 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPPublicKey; +import org.bouncycastle.openpgp.PGPPublicKeyRing; +import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; +import org.bouncycastle.openpgp.PGPSecretKey; +import org.bouncycastle.openpgp.PGPSecretKeyRing; +import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; +import org.bouncycastle.openpgp.PGPUtil; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Iterator; + +/** + * Bouncy Castle implementation of the OpenPGP key ring. + * + * @author Brett Porter + * @todo password is not secure + */ +public class BouncyCastleKeyRing + implements KeyRing +{ + private final PGPSecretKeyRingCollection pgpSec; + + private final char[] password; + + private final PGPPublicKeyRingCollection pgpPub; + + private static final long MASK = 0xFFFFFFFFL; + + public BouncyCastleKeyRing( InputStream secretKeyRingStream, InputStream publicKeyRingStream, char[] password ) + throws IOException, PGPException + { + pgpSec = new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( secretKeyRingStream ) ); + + pgpPub = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( publicKeyRingStream ) ); + + this.password = password; + } + + public char[] getPassword() + { + return password; + } + + public PGPSecretKey getSecretKey( String keyId ) + { + Iterator rIt = pgpSec.getKeyRings(); + + while ( rIt.hasNext() ) + { + PGPSecretKeyRing kRing = (PGPSecretKeyRing) rIt.next(); + Iterator kIt = kRing.getSecretKeys(); + + while ( kIt.hasNext() ) + { + PGPSecretKey k = (PGPSecretKey) kIt.next(); + + // TODO: do long conversion in other direction + if ( k.isSigningKey() && Long.toHexString( k.getKeyID() & MASK ).equals( keyId.toLowerCase() ) ) + { + return k; + } + } + } + + return null; + } + + public PGPPublicKey getPublicKey( String keyId ) + { + Iterator rIt = pgpPub.getKeyRings(); + + while ( rIt.hasNext() ) + { + PGPPublicKeyRing kRing = (PGPPublicKeyRing) rIt.next(); + Iterator kIt = kRing.getPublicKeys(); + + while ( kIt.hasNext() ) + { + PGPPublicKey k = (PGPPublicKey) kIt.next(); + + // TODO: do long conversion in other direction + if ( Long.toHexString( k.getKeyID() & MASK ).equals( keyId.toLowerCase() ) ) + { + return k; + } + } + } + + return null; + } + + public PGPSecretKey getSecretKey( long keyId ) + { + // TODO: switch with above + return getSecretKey( Long.toHexString( keyId & MASK ) ); + } + + public PGPPublicKey getPublicKey( long keyId ) + { + // TODO: switch with above + return getPublicKey( Long.toHexString( keyId & MASK ) ); + } +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleKeyRing.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignatureVerifier.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignatureVerifier.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignatureVerifier.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignatureVerifier.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,110 @@ +package org.apache.commons.openpgp; + +import org.bouncycastle.openpgp.PGPCompressedData; +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPObjectFactory; +import org.bouncycastle.openpgp.PGPPublicKey; +import org.bouncycastle.openpgp.PGPSignature; +import org.bouncycastle.openpgp.PGPSignatureList; +import org.bouncycastle.openpgp.PGPUtil; + +import java.io.IOException; +import java.io.InputStream; +import java.security.NoSuchProviderException; +import java.security.SignatureException; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Verify signatures using the Bouncy Castle OpenPGP provider. + * + * @author Brett Porter + */ +public class BouncyCastleOpenPgpSignatureVerifier + implements OpenPgpSignatureVerifier +{ + public SignatureStatus verifySignature( InputStream data, KeyRing keyRing ) + throws OpenPgpException, UnknownKeyException + { + // TODO: implement + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public SignatureStatus verifyDetachedSignature( InputStream data, InputStream signature, KeyRing keyRing ) + throws OpenPgpException, UnknownKeyException, IOException + { + signature = PGPUtil.getDecoderStream( signature ); + + PGPObjectFactory pgpFact = new PGPObjectFactory( signature ); + PGPSignatureList p3; + + try + { + Object o = pgpFact.nextObject(); + if ( o instanceof PGPCompressedData ) + { + PGPCompressedData c1 = (PGPCompressedData) o; + + pgpFact = new PGPObjectFactory( c1.getDataStream() ); + + p3 = (PGPSignatureList) pgpFact.nextObject(); + } + else + { + p3 = (PGPSignatureList) o; + } + + int ch; + + PGPSignature sig = p3.get( 0 ); + PGPPublicKey key = keyRing.getPublicKey( sig.getKeyID() ); + + sig.initVerify( key, "BC" ); + + while ( ( ch = data.read() ) >= 0 ) + { + sig.update( (byte) ch ); + } + + if ( sig.verify() ) + { + // TODO: how do we assess trust? + return SignatureStatus.VALID_UNTRUSTED; + } + else + { + return SignatureStatus.INVALID; + } + } + catch ( PGPException e ) + { + // TODO: more details + throw new OpenPgpException( "Error verifying detached signature", e ); + } + catch ( NoSuchProviderException e ) + { + throw new OpenPgpException( + "Unable to find the correct provider for PGP - check that the Bouncy Castle provider is correctly installed", + e ); + } + catch ( SignatureException e ) + { + // TODO: more details + throw new OpenPgpException( "Error calculating detached signature", e ); + } + } +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignatureVerifier.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignatureVerifier.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSigner.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSigner.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSigner.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSigner.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,107 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.bouncycastle.bcpg.ArmoredOutputStream; +import org.bouncycastle.bcpg.BCPGOutputStream; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPPrivateKey; +import org.bouncycastle.openpgp.PGPSecretKey; +import org.bouncycastle.openpgp.PGPSignature; +import org.bouncycastle.openpgp.PGPSignatureGenerator; +import org.bouncycastle.openpgp.PGPUtil; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Security; +import java.security.SignatureException; + +/** + * Bouncy Castle implementation of the OpenPGP signer. + * + * @author Brett Porter + */ +public class BouncyCastleOpenPgpSigner + implements OpenPgpSigner +{ + private static final String BOUNCY_CASTLE_PROVIDER = "BC"; + + public void sign( InputStream data, OutputStream signedOutput, String keyId, KeyRing keyRing, boolean asciiArmor ) + throws OpenPgpException + { + // TODO + } + + public void detachedSign( InputStream data, OutputStream signature, String keyId, KeyRing keyRing, + boolean asciiArmor ) + throws OpenPgpException, IOException + { + // TODO: necessary? + Security.addProvider( new BouncyCastleProvider() ); + if ( asciiArmor ) + { + signature = new ArmoredOutputStream( signature ); + } + + PGPSecretKey pgpSec = keyRing.getSecretKey( keyId ); + try + { + PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey( keyRing.getPassword(), BOUNCY_CASTLE_PROVIDER ); + PGPSignatureGenerator sGen = + new PGPSignatureGenerator( pgpSec.getPublicKey().getAlgorithm(), PGPUtil.SHA1, BOUNCY_CASTLE_PROVIDER ); + + sGen.initSign( PGPSignature.BINARY_DOCUMENT, pgpPrivKey ); + + BCPGOutputStream bOut = new BCPGOutputStream( signature ); + + int ch; + + while ( ( ch = data.read() ) >= 0 ) + { + sGen.update( (byte) ch ); + } + + sGen.generate().encode( bOut ); + } + catch ( NoSuchAlgorithmException e ) + { + throw new OpenPgpException( + "Unable to find the correct algorithm for PGP - check that the Bouncy Castle provider is correctly installed", + e ); + } + catch ( NoSuchProviderException e ) + { + throw new OpenPgpException( + "Unable to find the correct provider for PGP - check that the Bouncy Castle provider is correctly installed", + e ); + } + catch ( PGPException e ) + { + // TODO: more details + throw new OpenPgpException( "Error calculating detached signature", e ); + } + catch ( SignatureException e ) + { + // TODO: more details + throw new OpenPgpException( "Error calculating detached signature", e ); + } + } +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSigner.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSigner.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/KeyRing.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/KeyRing.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/KeyRing.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/KeyRing.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,62 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.bouncycastle.openpgp.PGPPublicKey; +import org.bouncycastle.openpgp.PGPSecretKey; + +/** + * Interface describing a key ring for use in signing or verifying data. + * + * @author Brett Porter + */ +public interface KeyRing +{ + /** + * @return + * @todo seems like the wrong place + */ + char[] getPassword(); + + /** + * @param keyId + * @return + * @todo remove BC specifics + */ + PGPSecretKey getSecretKey( String keyId ); + + /** + * @param keyId + * @return + * @todo remove BC specifics + */ + PGPPublicKey getPublicKey( String keyId ); + + /** + * @param keyId + * @return + * @todo remove BC specifics + */ + PGPSecretKey getSecretKey( long keyId ); + + /** + * @param keyId + * @return + * @todo remove BC specifics + */ + PGPPublicKey getPublicKey( long keyId ); +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/KeyRing.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/KeyRing.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpException.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpException.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpException.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpException.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,44 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * An exception occurring during the use of the OpenPGP library. + * + * @author Brett Porter + */ +public class OpenPgpException + extends Exception +{ + private Throwable cause; + + public OpenPgpException( String message ) + { + super( message ); + } + + public OpenPgpException( String message, Throwable cause ) + { + super( message ); + this.cause = cause; + } + + public Throwable getCause() + { + return cause; + } +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpException.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureUpdater.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureUpdater.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureUpdater.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureUpdater.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,56 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * An interface for updating an OpenPGP signature on the fly with streaming data. + * + * @author Brett Porter + * @todo not sure if this will be used or not + */ +public interface OpenPgpSignatureUpdater +{ + /** + * Update the signature with the next block from the data buffer. + * + * @param buf the buffer + * @throws OpenPgpException if the buffer is not valid for updating the signature + */ + void update( byte[] buf ) + throws OpenPgpException; + + /** + * Update the signature with the next block from the data buffer. + * + * @param buf the buffer + * @param offset offset within the buffer to start from + * @param length number of bytes in the buffer to read from + * @throws OpenPgpException if the buffer is not valid for updating the signature + */ + void update( byte[] buf, int offset, int length ) + throws OpenPgpException; + + /** + * Finish creating the signature. + * + * @return the completed signature + * @throws OpenPgpException if the signature is not in a consistent or complete state + */ + byte[] finish() + throws OpenPgpException; + +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureUpdater.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureUpdater.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureVerifier.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureVerifier.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureVerifier.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureVerifier.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,49 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.IOException; +import java.io.InputStream; + +/** + * Interface for verifying data signed with OpenPGP. + * + * @author Brett Porter + * @todo perhaps should have different interface methods for the default key + * @todo should the exception be a verification exception instead of a common one? + */ +public interface OpenPgpSignatureVerifier +{ + /** + * Verify a piece of data that was signed with OpenPGP. + * + * @param data the data that was signed + * @param keyRing the keyring containing the key used to sign the data + */ + SignatureStatus verifySignature( InputStream data, KeyRing keyRing ) + throws OpenPgpException, UnknownKeyException; + + /** + * Verify a piece of data against a detached signature. + * + * @param data the data to that was signed + * @param signature the detached signature to verify against the data + * @param keyRing the keyring containing the key used to sign the data + */ + SignatureStatus verifyDetachedSignature( InputStream data, InputStream signature, KeyRing keyRing ) + throws OpenPgpException, UnknownKeyException, IOException; +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureVerifier.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSignatureVerifier.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSigner.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSigner.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSigner.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSigner.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,55 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Interface for signing data with OpenPGP. + * + * @author Brett Porter + * @todo perhaps should have different interface methods for the default key + * @todo should the exception be a signature exception instead of a common one? + */ +public interface OpenPgpSigner +{ + /** + * Sign a piece of data with the given key. + * + * @param data the data to sign + * @param signedOutput the signed output data + * @param keyId the key ID of the key used to sign it + * @param keyRing the keyring containing the key above + * @param asciiArmor whether to ascii armor the output + */ + void sign( InputStream data, OutputStream signedOutput, String keyId, KeyRing keyRing, boolean asciiArmor ) + throws OpenPgpException; + + /** + * Sign a piece of data with the given key, storing the signature in a detached output. + * + * @param data the data to sign + * @param signature the detached signature + * @param keyId the key ID of the key used to sign it + * @param keyRing the keyring containing the key above + * @param asciiArmor whether to ascii armor the output + */ + void detachedSign( InputStream data, OutputStream signature, String keyId, KeyRing keyRing, boolean asciiArmor ) + throws OpenPgpException, IOException; +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSigner.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/OpenPgpSigner.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/SignatureStatus.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/SignatureStatus.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/SignatureStatus.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/SignatureStatus.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,74 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Enumerated type indicating the status of data that was signed. + *

+ * Values: + *

    + *
  • VALID_TRUSTED
  • + *
  • VALID_UNTRUSTED
  • + *
  • INVALID
  • + *
+ * + * @author Brett Porter + * @todo incorporate levels of trust + */ +public class SignatureStatus +{ + /** + * Status that indicates the signature is valid, and from a trusted source. + */ + public static SignatureStatus VALID_TRUSTED = new SignatureStatus( true, true ); + + /** + * Status that indicates the signature is valid, but from an unknown or untrusted source. + */ + public static SignatureStatus VALID_UNTRUSTED = new SignatureStatus( true, false ); + + /** + * Status that indicates the signature is invalid. + */ + public static SignatureStatus INVALID = new SignatureStatus( false, false ); + + /** + * Whether the signature is valid. + */ + private final boolean valid; + + /** + * Whether the signature is trusted. + */ + private final boolean trusted; + + private SignatureStatus( boolean valid, boolean trusted ) + { + this.valid = valid; + this.trusted = trusted; + } + + public boolean isValid() + { + return valid; + } + + public boolean isTrusted() + { + return trusted; + } +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/SignatureStatus.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/SignatureStatus.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/UnknownKeyException.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/UnknownKeyException.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/UnknownKeyException.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/UnknownKeyException.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,36 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * An exception occurring during the verification of a signature, when the key is not found in the keyring. + * + * @author Brett Porter + */ +public class UnknownKeyException + extends OpenPgpException +{ + public UnknownKeyException( String message ) + { + super( message ); + } + + public UnknownKeyException( String message, Throwable cause ) + { + super( message, cause ); + } +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/UnknownKeyException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/main/java/org/apache/commons/openpgp/UnknownKeyException.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignerTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignerTest.java?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignerTest.java (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignerTest.java Tue Dec 6 15:00:39 2005 @@ -0,0 +1,76 @@ +package org.apache.commons.openpgp; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * Test the open pgp signer. + * + * @author Brett Porter + */ +public class BouncyCastleOpenPgpSignerTest + extends TestCase +{ + private OpenPgpSigner signer = new BouncyCastleOpenPgpSigner(); + + private OpenPgpSignatureVerifier verifier = new BouncyCastleOpenPgpSignatureVerifier(); + + private String keyId = "A7D16BD4"; + + private KeyRing keyRing; + + private static final String PASSWORD = "cop"; + + protected void setUp() + throws Exception + { + super.setUp(); + + keyRing = new BouncyCastleKeyRing( getClass().getResourceAsStream( "/secring.gpg" ), + getClass().getResourceAsStream( "/pubring.gpg" ), PASSWORD.toCharArray() ); + } + + public void testSignDataDetachedBinary() + throws OpenPgpException, IOException + { + ByteArrayOutputStream signature = new ByteArrayOutputStream(); + signer.detachedSign( getClass().getResourceAsStream( "/test-input.txt" ), signature, keyId, keyRing, false ); + + // TODO: can we get it to verify an ascii armored one? + SignatureStatus status = verifier.verifyDetachedSignature( getClass().getResourceAsStream( "/test-input.txt" ), + new ByteArrayInputStream( signature.toByteArray() ), + keyRing ); + assertNotNull( "check we got a status", status ); + assertTrue( "check it was successful", status.isValid() ); + } + + public void testVerifySignatureDetachedAsciiArmor() + throws IOException, OpenPgpException + { + SignatureStatus status = verifier.verifyDetachedSignature( getClass().getResourceAsStream( "/test-input.txt" ), + getClass().getResourceAsStream( + "/test-signature.asc" ), keyRing ); + + assertNotNull( "check we got a status", status ); + assertTrue( "check it was successful", status.isValid() ); + } +} Propchange: jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/test/java/org/apache/commons/openpgp/BouncyCastleOpenPgpSignerTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/test/resources/pubring.gpg URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/test/resources/pubring.gpg?rev=354611&view=auto ============================================================================== Binary file - no diff available. Propchange: jakarta/commons/sandbox/openpgp/trunk/src/test/resources/pubring.gpg ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: jakarta/commons/sandbox/openpgp/trunk/src/test/resources/secring.gpg URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/test/resources/secring.gpg?rev=354611&view=auto ============================================================================== Binary file - no diff available. Propchange: jakarta/commons/sandbox/openpgp/trunk/src/test/resources/secring.gpg ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-input.txt URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-input.txt?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-input.txt (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-input.txt Tue Dec 6 15:00:39 2005 @@ -0,0 +1,10 @@ +The quick brown fox jumps over the lazy dog +quick brown fox jumps over the lazy dog The +brown fox jumps over the lazy dog The quick +fox jumps over the lazy dog The quick brown +jumps over the lazy dog The quick brown fox +over the lazy dog The quick brown fox jumps +the lazy dog The quick brown fox jumps over +lazy dog The quick brown fox jumps over the +dog The quick brown fox jumps over the lazy + Propchange: jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-input.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-input.txt ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-signature.asc URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-signature.asc?rev=354611&view=auto ============================================================================== --- jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-signature.asc (added) +++ jakarta/commons/sandbox/openpgp/trunk/src/test/resources/test-signature.asc Tue Dec 6 15:00:39 2005 @@ -0,0 +1,7 @@ +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.1 (Cygwin) + +iD8DBQBDlVJdTusOMqfRa9QRAuxXAJ9k0G+f2tbO6eTuBQS1uim44aADVwCgxS3i +MH8RP0v17V5sM1WN8ih97n8= +=gPJ5 +-----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org