public virtual void VerifySignature() { // Verify the certificate used to sign the package. var certificate = Certificate; if (!certificate.Verify()) { throw new Exception(Messages.CERTIFICATE_IS_INVALID); } // Get the package signature from the certificate file. FileDigest fileDigest = null; using (Stream stream = new MemoryStream(RawCertificate)) using (StreamReader reader = new StreamReader(stream)) { // The package signature is the digest of the file identified on the first line in the certificate file. fileDigest = new FileDigest(reader.ReadLine()); } // Compare the stored signature to the computed signature. // Do this independently to minimize the number of files opened concurrently. using (Stream stream = new MemoryStream(RawManifest)) { // Verify the signature using the public key. fileDigest.Verify(stream, (RSACryptoServiceProvider)certificate.PublicKey.Key); } }
public override void VerifyManifest() { // Verify the presence of a manifest. var manifest = Manifest; int verifiedCount = 0; using (var stream = new TarFileStream(PackageSourceFile)) { // For a tar package, it is more efficient to iterate the files in the order within the archive. while (MoveNext(stream)) { // Find the manifest entry for the current tar entry. FileDigest fileDigest = manifest.Find( delegate(FileDigest aFileDigest) { return(String.Compare(aFileDigest.Name, stream.Current, true) == 0); }); if (fileDigest == null) { continue; } // The manifest entry was found. // Verify its digest. fileDigest.Verify(new MemoryStream(stream.ReadAllBytes())); verifiedCount++; } foreach (var fileDigest in manifest) { if (!fileDigest.WasVerified) { // A manifest entry was missing. XenOvf.Utilities.Log.Error(string.Format(Messages.FILE_MISSING, fileDigest.Name)); } } if (verifiedCount != manifest.Count) { // A manifest entry was missing. throw new Exception(Messages.SECURITY_FILE_MISSING); } } }
public virtual void VerifySignature() { // Verify the certificate used to sign the package. var certificate = Certificate; if (!certificate.Verify()) { throw new Exception(Messages.CERTIFICATE_IS_INVALID); } // Get the package signature from the certificate file. FileDigest fileDigest = null; using (Stream stream = new MemoryStream(RawCertificate)) using (StreamReader reader = new StreamReader(stream)) { // The package signature is the digest of the file identified on the first line in the certificate file. fileDigest = new FileDigest(reader.ReadLine()); } // Compare the stored signature to the computed signature. // Do this independently to minimize the number of files opened concurrently. using (Stream stream = new MemoryStream(RawManifest)) { // Verify the signature using the public key. fileDigest.Verify(stream, (RSACryptoServiceProvider)certificate.PublicKey.Key); } }