forked from XML-Security/signxml
-
Notifications
You must be signed in to change notification settings - Fork 0
[ADD] issuer info #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ovnicraft
wants to merge
6
commits into
xoe-labs:master
Choose a base branch
from
ovnicraft:xades
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd15c36
WIP WIP
1005ede
[ADD] issuer info
fefd820
[IMP] correct alg for cert digest
f6db4d4
[IMP] PoC extending classes based on xades forms
87eb612
[IMP] b64 - DER encoding for serial_number
d3f57f8
Merge branch 'master' into xades
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -14,6 +14,9 @@ | |
from lxml.builder import ElementMaker | ||
from defusedxml.lxml import fromstring | ||
|
||
from OpenSSL.crypto import X509Name | ||
|
||
from cryptography.hazmat import _der | ||
from cryptography.hazmat.primitives.asymmetric import rsa, dsa, ec | ||
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15 | ||
from cryptography.hazmat.primitives.hashes import Hash, SHA1, SHA224, SHA256, SHA384, SHA512 | ||
|
@@ -57,6 +60,15 @@ def namedtuple_with_defaults(typename, field_names, default_values=()): | |
|
||
# helper functions | ||
|
||
class X509NamePKCS12(X509Name): | ||
def _issuer_string(self): | ||
x509name = self.get_components() | ||
x509name.reverse() | ||
return ",".join([f"{var.decode()}={alias.decode()}" for var, alias in x509name]) | ||
|
||
def issuer_string(certificate): | ||
return X509NamePKCS12(certificate.get_issuer())._issuer_string() | ||
|
||
def _gen_id(prefix, suffix=None): | ||
""" | ||
Generates the id | ||
|
@@ -75,7 +87,6 @@ def resolve_uri(uri): | |
except: | ||
raise InvalidInput(f"Unable to resolve reference URI: {uri}") | ||
|
||
|
||
class XAdESProcessor(XMLSignatureProcessor): | ||
schema_file = "v1.4.1/XAdES01903v141-201601.xsd" | ||
|
||
|
@@ -588,6 +599,37 @@ def _generate_xades(self, options_struct): | |
up := UnsignedProperties, c. 4.3.3 | ||
usp := UnignedSignatureProperties, c. 4.3.6 | ||
udop := UnignedDataObjectProperties, c. 4.3.7 | ||
|
||
Electronic signature forms elements | ||
Mention differences between nodes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
XaDES-BES | ||
ssp: | ||
(SigningTime)? | ||
(SigningCertificate)? | ||
(SignatureProductionPlace)? | ||
(SignerRole)? | ||
|
||
XaDES-EPES: | ||
ssp: | ||
(SigningTime)? | ||
(SigningCertificate)? | ||
(SignaturePolicyIdentifier) | ||
(SignatureProductionPlace)? | ||
(SignerRole)? | ||
|
||
XaDES-T: | ||
usp: | ||
(CounterSignature)* | ||
(SignatureTimeStamp)+ | ||
|
||
XaDES-C: | ||
usp: | ||
(CounterSignature) | ||
(SignatureTimeStamp) | ||
(CompleteCertificateRefs) | ||
(CompleteRevocationRefs) | ||
(AttributeCertificateRefs)? | ||
(AttributeRevocationRefs)? | ||
ovnicraft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
|
||
ssp_elements = self._generate_xades_ssp_elements(options_struct) | ||
|
@@ -712,3 +754,46 @@ def _generate_xades(self, options_struct): | |
qp = XADES.QualifyingProperties(*qp_elements, **qp_attributes) | ||
self._add_xades_reference(qp) | ||
return qp | ||
|
||
|
||
class XAdESEPESSigner(XAdESSigner): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be an excellent idea, I have to think around it a bit.. Thanks 👍 |
||
|
||
def _generate_xades_ssp_elements(self, options_struct): | ||
# Item 4: SignaturePolicyIdentifier | ||
""" | ||
The SignaturePolicyIdentifier qualifying property shall be a signed | ||
qualifying property qualifying the signature. | ||
The SignaturePolicyIdentifier qualifying property shall contain either | ||
an explicit identifier of a signature policy or an indication that | ||
there is an implied signature policy that the relying party should | ||
be aware of. | ||
|
||
ETSI TS 119 172-1 specifies a framework for signature policies. | ||
""" | ||
elements = super(XAdESEPESSigner, self)._generate_xades_ssp_elements(options_struct) | ||
spid_elements = [] | ||
sp = options_struct.SignaturePolicy | ||
# digest method | ||
pdm = self.known_digest_tags.get(self.digest_alg) | ||
# digest value | ||
pv = resolve_uri(sp.Identifier) | ||
|
||
spid_elements.append( | ||
XADES132.SigPolicyId( | ||
XADES132.Identifier(sp.Identifier), | ||
XADES132.Description(sp.Description) | ||
) | ||
) | ||
spid_elements.append( | ||
XADES132.SigPolicyHash( | ||
DS.DigestMethod(Algorithm=pdm), | ||
DS.DigestValue( | ||
self._get_digest(pv,self._get_digest_method_by_tag(self.digest_alg)) | ||
) | ||
) | ||
) | ||
spid = XADES132.SignaturePolicyId(*spid_elements) | ||
spi_elements = [] | ||
spi_elements.append(spid) | ||
elements.append(XADES132.SignaturePolicyIdentifier(*spi_elements)) | ||
return elements |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Electronic signature grammar (I guess that's what it is) by mode"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
term used https://www.etsi.org/deliver/etsi_ts/101900_101999/101903/01.04.02_60/ts_101903v010402p.pdf at 4.4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with that, just those
?
look a little grammar-ish. But yep, in xml, that is probably not a common usage of a word...