本文整理匯總了Java中java.security.CodeSigner類的典型用法代碼示例。如果您正苦於以下問題:Java CodeSigner類的具體用法?Java CodeSigner怎麽用?Java CodeSigner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CodeSigner類屬於java.security包,在下文中一共展示了CodeSigner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSigningCertFromJar
import java.security.CodeSigner; //導入依賴的package包/類
/**
* FDroid's index.jar is signed using a particular format and does not allow lots of
* signing setups that would be valid for a regular jar. This validates those
* restrictions.
*/
X509Certificate getSigningCertFromJar(JarEntry jarEntry) throws SigningException {
final CodeSigner[] codeSigners = jarEntry.getCodeSigners();
if (codeSigners == null || codeSigners.length == 0) {
throw new SigningException(repo, "No signature found in index");
}
/* we could in theory support more than 1, but as of now we do not */
if (codeSigners.length > 1) {
throw new SigningException(repo, "index.jar must be signed by a single code signer!");
}
List<? extends Certificate> certs = codeSigners[0].getSignerCertPath().getCertificates();
if (certs.size() != 1) {
throw new SigningException(repo, "index.jar code signers must only have a single certificate!");
}
return (X509Certificate) certs.get(0);
}
示例2: SignatureFileVerifier
import java.security.CodeSigner; //導入依賴的package包/類
/**
* Create the named SignatureFileVerifier.
*
* @param name the name of the signature block file (.DSA/.RSA/.EC)
*
* @param rawBytes the raw bytes of the signature block file
*/
public SignatureFileVerifier(ArrayList<CodeSigner[]> signerCache,
ManifestDigester md,
String name,
byte rawBytes[])
throws IOException, CertificateException
{
// new PKCS7() calls CertificateFactory.getInstance()
// need to use local providers here, see Providers class
Object obj = null;
try {
obj = Providers.startJarVerification();
block = new PKCS7(rawBytes);
sfBytes = block.getContentInfo().getData();
certificateFactory = CertificateFactory.getInstance("X509");
} finally {
Providers.stopJarVerification(obj);
}
this.name = name.substring(0, name.lastIndexOf("."))
.toUpperCase(Locale.ENGLISH);
this.md = md;
this.signerCache = signerCache;
}
示例3: process
import java.security.CodeSigner; //導入依賴的package包/類
/**
* process the signature block file. Goes through the .SF file
* and adds code signers for each section where the .SF section
* hash was verified against the Manifest section.
*
*
*/
public void process(Hashtable<String, CodeSigner[]> signers,
List<Object> manifestDigests)
throws IOException, SignatureException, NoSuchAlgorithmException,
JarException, CertificateException
{
// calls Signature.getInstance() and MessageDigest.getInstance()
// need to use local providers here, see Providers class
Object obj = null;
try {
obj = Providers.startJarVerification();
processImpl(signers, manifestDigests);
} finally {
Providers.stopJarVerification(obj);
}
}
示例4: SignatureFileVerifier
import java.security.CodeSigner; //導入依賴的package包/類
/**
* Create the named SignatureFileVerifier.
*
* @param name the name of the signature block file (.DSA/.RSA/.EC)
*
* @param rawBytes the raw bytes of the signature block file
*/
public SignatureFileVerifier(ArrayList<CodeSigner[]> signerCache,
ManifestDigester md,
String name,
byte[] rawBytes)
throws IOException, CertificateException
{
// new PKCS7() calls CertificateFactory.getInstance()
// need to use local providers here, see Providers class
Object obj = null;
try {
obj = Providers.startJarVerification();
block = new PKCS7(rawBytes);
sfBytes = block.getContentInfo().getData();
certificateFactory = CertificateFactory.getInstance("X509");
} finally {
Providers.stopJarVerification(obj);
}
this.name = name.substring(0, name.lastIndexOf('.'))
.toUpperCase(Locale.ENGLISH);
this.md = md;
this.signerCache = signerCache;
}
示例5: findSource
import java.security.CodeSigner; //導入依賴的package包/類
static CodeSource findSource(ClassLoader loader, String name) {
String fileName = name.replace('.', '/') + ".class";
URL url = loader.getResource(fileName);
if (url == null) return null;
CodeSigner[] signers = null;
if (name.lastIndexOf('.') > -1) {
try {
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
JarURLConnection jarConnection = (JarURLConnection) connection;
url = jarConnection.getJarFileURL();
JarFile jarFile = jarConnection.getJarFile();
if (jarFile != null && jarFile.getManifest() != null) {
signers = jarFile.getJarEntry(fileName).getCodeSigners();
}
}
} catch (IOException e) {
return null;
}
}
return new CodeSource(url, signers);
}
示例6: getSigningCertFromJar
import java.security.CodeSigner; //導入依賴的package包/類
/**
* FDroid's index.jar is signed using a particular format and does not allow lots of
* signing setups that would be valid for a regular jar. This validates those
* restrictions.
*/
private X509Certificate getSigningCertFromJar(JarEntry jarEntry) throws SigningException {
final CodeSigner[] codeSigners = jarEntry.getCodeSigners();
if (codeSigners == null || codeSigners.length == 0) {
throw new SigningException(repo, "No signature found in index");
}
/* we could in theory support more than 1, but as of now we do not */
if (codeSigners.length > 1) {
throw new SigningException(repo, "index.jar must be signed by a single code signer!");
}
List<? extends Certificate> certs = codeSigners[0].getSignerCertPath().getCertificates();
if (certs.size() != 1) {
throw new SigningException(repo, "index.jar code signers must only have a single certificate!");
}
return (X509Certificate) certs.get(0);
}
示例7: testManyEntriesSingleValidSigner
import java.security.CodeSigner; //導入依賴的package包/類
@Test
public void testManyEntriesSingleValidSigner() throws Exception {
JarCertVerifier jcv = new JarCertVerifier(null);
CodeSigner[] signers = { alphaSigner };
Vector<JarEntry> entries = new Vector<JarEntry>();
entries.add(new JarCertVerifierEntry("firstSignedByOne", signers));
entries.add(new JarCertVerifierEntry("secondSignedByOne", signers));
entries.add(new JarCertVerifierEntry("thirdSignedByOne", signers));
VerifyResult result = jcv.verifyJarEntryCerts("", true, entries);
Assert.assertEquals("Three entries signed by one signer should be considered signed and okay.",
VerifyResult.SIGNED_OK, result);
Assert.assertEquals("Three entries signed by one signer means one signer in the verifier.",
1, jcv.getCertsList().size());
Assert.assertTrue("Three entries signed by one signer means one signer in the verifier.",
jcv.getCertsList().contains(alphaSigner.getSignerCertPath()));
}
示例8: testSingleEntryMultipleValidSigners
import java.security.CodeSigner; //導入依賴的package包/類
@Test
public void testSingleEntryMultipleValidSigners() throws Exception {
JarCertVerifier jcv = new JarCertVerifier(null);
CodeSigner[] signers = { alphaSigner, betaSigner, charlieSigner };
Vector<JarEntry> entries = new Vector<JarEntry>();
entries.add(new JarCertVerifierEntry("firstSignedByThree", signers));
VerifyResult result = jcv.verifyJarEntryCerts("", true, entries);
Assert.assertEquals("One entry signed by three signers should be considered signed and okay.",
VerifyResult.SIGNED_OK, result);
Assert.assertEquals("One entry signed by three means three signers in the verifier.",
3, jcv.getCertsList().size());
Assert.assertTrue("One entry signed by three means three signers in the verifier.",
jcv.getCertsList().contains(alphaSigner.getSignerCertPath())
&& jcv.getCertsList().contains(betaSigner.getSignerCertPath())
&& jcv.getCertsList().contains(charlieSigner.getSignerCertPath()));
}
示例9: testManyEntriesMultipleValidSigners
import java.security.CodeSigner; //導入依賴的package包/類
@Test
public void testManyEntriesMultipleValidSigners() throws Exception {
JarCertVerifier jcv = new JarCertVerifier(null);
CodeSigner[] signers = { alphaSigner, betaSigner, charlieSigner };
Vector<JarEntry> entries = new Vector<JarEntry>();
entries.add(new JarCertVerifierEntry("firstSignedByThree", signers));
entries.add(new JarCertVerifierEntry("secondSignedByThree", signers));
entries.add(new JarCertVerifierEntry("thirdSignedByThree", signers));
VerifyResult result = jcv.verifyJarEntryCerts("", true, entries);
Assert.assertEquals("Three entries signed by three signers should be considered signed and okay.",
VerifyResult.SIGNED_OK, result);
Assert.assertEquals("Three entries signed by three means three signers in the verifier.",
3, jcv.getCertsList().size());
Assert.assertTrue("Three entries signed by three means three signers in the verifier.",
jcv.getCertsList().contains(alphaSigner.getSignerCertPath())
&& jcv.getCertsList().contains(betaSigner.getSignerCertPath())
&& jcv.getCertsList().contains(charlieSigner.getSignerCertPath()));
}
示例10: testOneCommonSigner
import java.security.CodeSigner; //導入依賴的package包/類
@Test
public void testOneCommonSigner() throws Exception {
JarCertVerifier jcv = new JarCertVerifier(null);
CodeSigner[] alphaSigners = { alphaSigner };
CodeSigner[] betaSigners = { alphaSigner, betaSigner };
CodeSigner[] charlieSigners = { alphaSigner, charlieSigner };
Vector<JarEntry> entries = new Vector<JarEntry>();
entries.add(new JarCertVerifierEntry("firstSignedByOne", alphaSigners));
entries.add(new JarCertVerifierEntry("secondSignedByTwo", betaSigners));
entries.add(new JarCertVerifierEntry("thirdSignedByTwo", charlieSigners));
VerifyResult result = jcv.verifyJarEntryCerts("", true, entries);
Assert.assertEquals("Three entries signed by at least one common signer should be considered signed and okay.",
VerifyResult.SIGNED_OK, result);
Assert.assertEquals("Three entries signed completely by only one signer means one signer in the verifier.",
1, jcv.getCertsList().size());
Assert.assertTrue("Three entries signed completely by only one signer means one signer in the verifier.",
jcv.getCertsList().contains(alphaSigner.getSignerCertPath()));
}
示例11: testNoCommonSigner
import java.security.CodeSigner; //導入依賴的package包/類
@Test
public void testNoCommonSigner() throws Exception {
JarCertVerifier jcv = new JarCertVerifier(null);
CodeSigner[] alphaSigners = { alphaSigner };
CodeSigner[] betaSigners = { betaSigner };
CodeSigner[] charlieSigners = { charlieSigner };
Vector<JarEntry> entries = new Vector<JarEntry>();
entries.add(new JarCertVerifierEntry("firstSignedByAlpha", alphaSigners));
entries.add(new JarCertVerifierEntry("secondSignedByBeta", betaSigners));
entries.add(new JarCertVerifierEntry("thirdSignedByCharlie", charlieSigners));
VerifyResult result = jcv.verifyJarEntryCerts("", true, entries);
Assert.assertEquals("Three entries signed by no common signers should be considered unsigned.",
VerifyResult.UNSIGNED, result);
Assert.assertEquals("Three entries signed by no common signers means no signers in the verifier.",
0, jcv.getCertsList().size());
}
示例12: testFewButNotAllCommonSigners
import java.security.CodeSigner; //導入依賴的package包/類
@Test
public void testFewButNotAllCommonSigners() throws Exception {
JarCertVerifier jcv = new JarCertVerifier(null);
CodeSigner[] alphaSigners = { alphaSigner };
CodeSigner[] betaSigners = { betaSigner };
Vector<JarEntry> entries = new Vector<JarEntry>();
entries.add(new JarCertVerifierEntry("firstSignedByAlpha", alphaSigners));
entries.add(new JarCertVerifierEntry("secondSignedByAlpha", alphaSigners));
entries.add(new JarCertVerifierEntry("thirdSignedByBeta", betaSigners));
VerifyResult result = jcv.verifyJarEntryCerts("", true, entries);
Assert.assertEquals("First two entries signed by alpha signer, third entry signed by beta signer should be considered unisgned.",
VerifyResult.UNSIGNED, result);
Assert.assertEquals("Three entries signed by some common signers but not all means no signers in the verifier.",
0, jcv.getCertsList().size());
}
示例13: testManyEntriesExpiredSigner
import java.security.CodeSigner; //導入依賴的package包/類
@Test
public void testManyEntriesExpiredSigner() throws Exception {
JarCertVerifier jcv = new JarCertVerifier(null);
CodeSigner[] expiredSigners = { expiredSigner };
Vector<JarEntry> entries = new Vector<JarEntry>();
entries.add(new JarCertVerifierEntry("firstSignedByExpired", expiredSigners));
entries.add(new JarCertVerifierEntry("secondSignedBExpired", expiredSigners));
entries.add(new JarCertVerifierEntry("thirdSignedByExpired", expiredSigners));
VerifyResult result = jcv.verifyJarEntryCerts("", true, entries);
Assert.assertEquals("Three entries signed by expired cert, should be considered signed but not okay.",
VerifyResult.SIGNED_NOT_OK, result);
Assert.assertEquals("Three entries signed by expired cert means one signer in the verifier.",
1, jcv.getCertsList().size());
Assert.assertTrue("Three entries signed by expired cert means one signer in the verifier.",
jcv.getCertsList().contains(expiredSigner.getSignerCertPath()));
}
示例14: testManyEntriesExpiringSigner
import java.security.CodeSigner; //導入依賴的package包/類
@Test
public void testManyEntriesExpiringSigner() throws Exception {
JarCertVerifier jcv = new JarCertVerifier(null);
CodeSigner[] expiringSigners = { expiringSigner };
Vector<JarEntry> entries = new Vector<JarEntry>();
entries.add(new JarCertVerifierEntry("firstSignedByExpiring", expiringSigners));
entries.add(new JarCertVerifierEntry("secondSignedBExpiring", expiringSigners));
entries.add(new JarCertVerifierEntry("thirdSignedByExpiring", expiringSigners));
VerifyResult result = jcv.verifyJarEntryCerts("", true, entries);
Assert.assertEquals("Three entries signed by expiring cert, should be considered signed and okay.",
VerifyResult.SIGNED_OK, result);
Assert.assertEquals("Three entries signed by expiring cert means one signer in the verifier.",
1, jcv.getCertsList().size());
Assert.assertTrue("Three entries signed by expiring cert means one signer in the verifier.",
jcv.getCertsList().contains(expiringSigner.getSignerCertPath()));
}
示例15: testManyEntriesNotYetValidSigner
import java.security.CodeSigner; //導入依賴的package包/類
@Test
public void testManyEntriesNotYetValidSigner() throws Exception {
JarCertVerifier jcv = new JarCertVerifier(null);
CodeSigner[] notYetValidSigners = { notYetValidSigner };
Vector<JarEntry> entries = new Vector<JarEntry>();
entries.add(new JarCertVerifierEntry("firstSignedByNotYetValid", notYetValidSigners));
entries.add(new JarCertVerifierEntry("secondSignedByNotYetValid", notYetValidSigners));
entries.add(new JarCertVerifierEntry("thirdSignedByNotYetValid", notYetValidSigners));
VerifyResult result = jcv.verifyJarEntryCerts("", true, entries);
Assert.assertEquals("Three entries signed by cert that is not yet valid, should be considered signed but not okay.",
VerifyResult.SIGNED_NOT_OK, result);
Assert.assertEquals("Three entries signed by cert that is not yet valid means one signer in the verifier.",
1, jcv.getCertsList().size());
Assert.assertTrue("Three entries signed by cert that is not yet valid means one signer in the verifier.",
jcv.getCertsList().contains(notYetValidSigner.getSignerCertPath()));
}