-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from dghgit/master
addition of pre-hash certificates
- Loading branch information
Showing
4 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains 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 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,77 @@ | ||
import java.io.ByteArrayInputStream; | ||
import java.io.FileInputStream; | ||
import java.io.FileReader; | ||
import java.security.Security; | ||
import java.security.cert.CertificateFactory; | ||
import java.security.cert.X509Certificate; | ||
|
||
import org.bouncycastle.cert.X509CertificateHolder; | ||
import org.bouncycastle.jcajce.provider.asymmetric.X509; | ||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
import org.bouncycastle.openssl.PEMParser; | ||
import org.bouncycastle.util.io.Streams; | ||
|
||
public class Verify | ||
{ | ||
public static void main(String[] args) | ||
throws Exception | ||
{ | ||
Security.addProvider(new BouncyCastleProvider()); | ||
|
||
CertificateFactory certFact = CertificateFactory.getInstance("X.509", "BC"); | ||
|
||
if (args.length != 2) | ||
{ | ||
System.out.println("usage: " + "Verify self-signed <certfile>"); | ||
} | ||
else if (args[0].equals("self-signed")) | ||
{ | ||
byte[] data = null; | ||
if (args[1].endsWith(".pem")) | ||
{ | ||
PEMParser pemPrs = new PEMParser(new FileReader(args[1])); | ||
|
||
X509CertificateHolder hld = (X509CertificateHolder)pemPrs.readObject(); | ||
|
||
pemPrs.close(); | ||
|
||
data = hld.getEncoded(); | ||
} | ||
else if (args[1].endsWith(".der")) | ||
{ | ||
FileInputStream fIn = new FileInputStream((args[1])); | ||
|
||
data = Streams.readAll(fIn); | ||
|
||
fIn.close(); | ||
} | ||
else | ||
{ | ||
System.out.println("unknown file: " + args[1]); | ||
System.exit(1); | ||
} | ||
|
||
X509Certificate cert = (X509Certificate)certFact.generateCertificate(new ByteArrayInputStream(data)); | ||
|
||
try | ||
{ | ||
cert.verify(cert.getPublicKey()); | ||
|
||
System.out.println(args[1] + " verified"); | ||
System.exit(0); | ||
} | ||
catch (Exception e) | ||
{ | ||
System.out.println(args[1] + " failed verification"); | ||
System.exit(1); | ||
} | ||
} | ||
else | ||
{ | ||
System.out.println("unknown command: " + args[0]); | ||
} | ||
|
||
System.exit(1); | ||
} | ||
} | ||
|
This file contains 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,12 @@ | ||
#!/bin/bash | ||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
set -e | ||
|
||
|
||
cd $SCRIPT_DIR | ||
|
||
base=`cat lib/beta.ver` | ||
|
||
javac -d classes -cp lib/bcprov-${base}.jar:lib/bcutil-${base}.jar:lib/bcpkix-${base}.jar src/main/java/*.java | ||
|
||
java -cp classes:lib/bcprov-${base}.jar:lib/bcutil-${base}.jar:lib/bcpkix-${base}.jar Verify self-signed $1 |