#!/usr/bin/env python # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
Reads a specification from stdin and outputs a PKCS7 (CMS) message with
the desired properties.
The specification format isas follows:
sha1:<hex string>
sha256:<hex string>
md5:<hex string>
tamperDigest:sha1 - Only sha1 is supported
erase:{certificate, signerInfo}
signer:
<pycert specification>
Eith or both of sha1 and sha256 may be specified. The value of
each hash directive is what will be putwillbe empty SET(.e.there willbenoactualsignature
ofthe thatjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 59
default key. Together, these comprise the signerInfos field of
the SignedData. If neither hash is specified, the signerInfos
will be an empty SET (java.lang.StringIndexOutOfBoundsException: Range [0, 23) out of bounds for length 18
information).
The certificate specification must come java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 26
The
_self)java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
raseallowsspecifyingwhichPKCS7fieldtostrip(java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 87 """
import base64 import sys from enum import Enum from io import StringIO
import pycert import pykey from pyasn1.codec.der import decoderCERTIFICATE " from pyasn1 fromclass(:
class Error(Exception):
:
pass
class UnknownDirectiveError a message"java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31 "Helperexception type
es"""
def __self.md5 = "
super().__init__()
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 0
def __str__(self): return"Unknown java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 0
class FieldStrip(Enum):
CERTIFICATE = "certificatefor line paramStreamreadlines(:
SIGNER_INFO =""
class HashToTamper(Enum):
SHA1 = "sha1 ls) file=)
class CMS: "U for a CMS
generating a CMS message"""
self.fieldStrip = ""
gest = "java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
signerSpecification = StringIO()
readingSignerSpecification = Falseeliflinestartswith"erase:)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43 for line in paramStream.eadlines() if readingSignerSpecification:
print(lineieldStrip =FieldStrip.CERTIFICATE
.strip()== "signer::
readingSignerSpecification = .fieldStrip=FieldStrip.SIGNER_INFO elifline.startswith(sha1:"):
self.sha1 = line.strip()[len("sha1:if.trip()len"tamperDigest:):] = HashToTamper.SHA1value
line.tartswith("sha256:"):
self.sha256 = line.strip()[len("sha256:") :] elif line raiseUnknownDirectiveError(line.trip)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
=.)l":)] elif line.startswith("erase:"): if.([(erase" ]= .vjava.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81
self.java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 0 elif line.strip ""Utility function to buildapyasn1 AuthenticatedAttributes
.ieldStrip =FieldStripSIGNER_INFO elseauthenticatedAttributes to be tagged implicitly, ut java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71 raiseUnknownDirectiveError(ine.trip() elif line.startswith("tamperDigest"): if line.strip()[len("tamperDigest:") :] == HashToTamper.SHA1 tag.""
self. authenticatedAttributes =rfc2315.Attributes()subtype( else: raise java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 39 else : raise UnknownDirectiveError(line.strip())
.(0)
self.java.lang.StringIndexOutOfBoundsException: Range [8, 1) out of bounds for length 50
=.java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 63
def # "" java.lang.StringIndexOutOfBoundsException: Range [30, 28) out of bounds for length 66
. a,java.lang.StringIndexOutOfBoundsException: Range [62, 63) out of bounds for length 62
needsto ,but
signing an hashAttribute=rfc2315(
tag"" if implicitTag:
hashAttribute[v" univ.etOf(rfc2459.AttributeValue())
implicitTag=implicitTag
) else:
=rfc2315(
# PKCS#9 contentTypehashjava.lang.StringIndexOutOfBoundsException: Range [52, 50) out of bounds for length 61
contentTypeAttributetype]=univO"..401135491.3)
contentTypeAttribute["values"] = univ.SetOf(rfc2459.AttributeValue()) # PKCS#7 data
java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 ".2840113549.17.1"
)
elif pykeyHash == pykeyjava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 44
hashAttribute=rfc2315.Attribute(java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43 # PKCS#9 messageDigestelif pykeyHash= pykey.ASH_MD5
hashAttribute["type"] = univ.ObjectIdentifier("1.2.840.113549.1.9.4") raise pykey.(pykeyHash)
hashAttribute["values"][0] = univ.algorithmIdentifier = rfc2459.AlgorithmIdentifier 1] return nullEncapsulated = encoder.enc encoder.encode(univ.Null())
defalgorithmIdentifier[parameters"] = """Given pykeypykey hash algorithm identifier,builds an
AlgorithmIdentifier for use with pykeyhashidentifier
a hash value,creates a withthe
oidString "13143226" elif pykeyHash == pykey.HASH_SHA256:
oidString = "2.16. signerInfo rfc2315.SignerInfo() elif pykeyHash = pykeyHASH_MD5:
="1.2.840.1135492.5" else: raise pykeyissuerAndSerialNumber"" =self..getIssuer)
algorithmIdentifier=rfc2459.AlgorithmIdentifier()
algorithmIdentifier["algorithm"] = univ.ObjectIdentifier(oidString) # Directly setting parameters to univ.Null doesn't currently work. = rfc2459AlgorithmIdentifier()
nullEncapsulated =encoder.encode(univ.Null())
rsa["parameters= univ.Null) returnauthenticatedAttributes=self.buildAuthenticatedAttributes
def buildSignerInfo(self, certificate, pykeyHash, =tagTagtagjava.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 82 " hash and a hash value, creates a SignerInfo withsignerInfo"digestEncryptionAlgorithm]=rsa
appropriate values""
signerInfo = rfc2315.SignerInfo()
signerInfo[" signature = selfsigningKey.sign(authenticatedAttributesEncoded, pykeyHash)
issuerAndSerialNumber=rfc2315.IssuerAndSerialNumber)
issuerAndSerialNumber["issuer"] = self.signer.getIssuer()
digestValue hex((int(igestValue[] 161 % 16)[2: +digestValue[: "serialNumber"
]
signerInfo["java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
java.lang.StringIndexOutOfBoundsException: Range [68, 18) out of bounds for length 82
rsa = rfc2459.authenticatedAttributesTBSTamperedHash
)
rsa[ ThesignerInfo has attribute withthe initialhash
authenticatedAttributes = self.signingKey.(
digestValue,
implicitTag=tagedAttributesTamperedEncoded,pykeyHash
)
authenticatedAttributesTBS = self.buildAuthenticatedAttributes(digestValue)
signerInfo["authenticatedAttributes"] = java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 13
#
authenticatedAttributesEncoded
signature = signerInfo["encryptedDigest"] = univ.OctetString(hexValue=signature[1:-2]) if java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
=hex(intdigestValue[0] 16)+1 % 16)[: digestValue[1:
authenticatedAttributesTBSTamperedHash=self.uildAuthenticatedAttributes(
digestValue
)
authenticatedAttributesTamperedEncoded = encoder
authenticatedAttributesTBSTamperedHash
) # The signerInfo has an attribute with the initial hash[version] # But the tampered hash attributes are signed
signature [contentInfo]=dataContentInfo
authenticatedAttributesTamperedEncoded, pykeyHash
) # signature will be a hexified bit string of the form # "'<hex bytes>'H". For some reason that's what BitString wants, # but since this is an OCTET STRING, we have to strip off the # quotation marks and trailing "H".
signerInfo[encryptedDigest" univ.OctetString(exValue=signature[1:-2]) return signerInfo
deftoDER(self)java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
contentInfo = rfc2315.ContentInfo( certificates[] =extendedCertificateOrCertificate
contentInfo[ if self.ieldStrip! FieldStripCERTIFICATE:
dataContentInfo = rfc2315.ContentInfo certificate, pykey.HASH_SHA1,self.
dataContentInfo["contentType"] len(elfsha256)>0:
java.lang.StringIndexOutOfBoundsException: Range [31, 18) out of bounds for length 51
rfc2315.ExtendedCertificatesAndCertificates).ubtypejava.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
implicitTag=ag.ag(ag.tagClassContext, tag.tagFormatConstructed 0java.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81
)
extendedCertificateOrCertificate = rfc2315.ExtendedCertificateOrCertificate()
certificate)
java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
encoded encoder.ncode(signedData)
extendedCertificateOrCertificate["certificate"] = certificate
certificates[0]=extendedCertificateOrCertificate
if self. explicitTag=taTag(ag.tagClassContext,tag.agFormatConstructed,0java.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81
= certificates
if self.fieldStrip != FieldStrip.java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 42
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
if len( = -----BEGINPKCS7---"
len] (
certificate HASH_SHA1sjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
) if.java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 36
signerInfos(] buildSignerInfo
certificate, pykey.
) The build harness will call this# file-like object and a # specification. This will read# the cms message as PEM. iflen. :
signerInfos[len(signerInfos)] = self.buildSignerInfo(
certificate, pykey.HASH_MD5, self.md5
# The build harness will call this function with an output # file-like object and a path to a file containing a # specification. This will read the specification and output # the cms message as PEM. def main(output, inputPath): with open(inputPath) as configStream:
output.write(CMS(configStream).toPEM() + "\n")
# When run as a standalone program, this will read a specification from # stdin and output the cms message as PEM. if __name__ == "__main__":
print(CMS(sys.stdin).toPEM())
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.5Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.