├── src ├── XAdESException.php ├── KeyResourceInfo.php ├── CertificateResourceInfo.php ├── xml │ ├── SignaturePolicyBase.php │ ├── UnsignedSignatureProperty.php │ ├── SignaturePolicyImplied.php │ ├── SignedAssertion.php │ ├── SPURI.php │ ├── DocumentationReference.php │ ├── City.php │ ├── Description.php │ ├── MimeType.php │ ├── PostalCode.php │ ├── ClaimedRole.php │ ├── CountryName.php │ ├── ExplicitText.php │ ├── Organization.php │ ├── SigPolicyId.php │ ├── StreetAddress.php │ ├── SigPolDocLocalURI.php │ ├── ObjectReference.php │ ├── StateOrProvince.php │ ├── IssuerSerialV2.php │ ├── OtherValue.php │ ├── SPDocSpecification.php │ ├── AttributeNames.php │ ├── SignaturePolicyDocument.php │ ├── CommitmentTypeQualifier.php │ ├── OtherAttributeCertificate.php │ ├── EncapsulatedTimeStamp.php │ ├── RefsOnlyTimeStamp.php │ ├── SigAndRefsTimeStamp.php │ ├── EncapsulatedCRLValue.php │ ├── EncapsulatedX509Certificate.php │ ├── EncapsulatedOCSPValue.php │ ├── IndividualDataObjectsTimeStamp.php │ ├── AttributeRevocationRefs.php │ ├── AttrAuthoritiesCertValues.php │ ├── AttributeRevocationValues.php │ ├── CommitmentTypeId.php │ ├── AttributeCertificateRefs.php │ ├── AllSignedDataObjects.php │ ├── SigningTime.php │ ├── CertDigest.php │ ├── Integer.php │ ├── X509IssuerName.php │ ├── AttributeCertificateRefsV2.php │ ├── RefsOnlyTimeStampV2.php │ ├── X509SerialNumber.php │ ├── X509Certificate.php │ ├── SigAndRefsTimeStampV2.php │ ├── ArchiveTimeStamp.php │ ├── SignatureTimeStamp.php │ ├── DigestValue.php │ ├── CRLRefs.php │ ├── SigPolicyQualifier.php │ ├── XPathFilter.php │ ├── NoticeNumbers.php │ ├── Encoding.php │ ├── CounterSignature.php │ ├── CanonicalizationMethod.php │ ├── CertifiedRole.php │ ├── SignatureMethod.php │ ├── OtherRef.php │ ├── X509AttributeCertificate.php │ ├── AllDataObjectsTimeStamp.php │ ├── XMLTimeStamp.php │ ├── OtherCertificate.php │ ├── SignatureValue.php │ ├── TextBase.php │ ├── OCSPRefs.php │ ├── OtherRefs.php │ ├── CertRefs.php │ ├── ClaimedRoles.php │ ├── CRLValues.php │ ├── CertificateValues.php │ ├── ReferenceInfo.php │ ├── Base64String.php │ ├── CommitmentTypeQualifiers.php │ ├── DocumentationReferences.php │ ├── OCSPValues.php │ ├── OtherValues.php │ ├── SignedAssertions.php │ ├── CertRefsV2.php │ ├── CertifiedRoles.php │ ├── SigPolicyQualifiers.php │ ├── EncapsulatedPKIData.php │ ├── CertifiedRolesV2.php │ ├── UnsignedDataObjectProperties.php │ ├── DigestMethod.php │ ├── TransformXPathFilter2.php │ ├── Incl.php │ ├── UnsignedSignatureProperties.php │ ├── XPathFilter2.php │ ├── CompleteCertificateRefs.php │ ├── ResponderID.php │ ├── SigPolicyHash.php │ ├── CompleteCertificateRefsV2.php │ ├── DigestAlgAndValue.php │ ├── Cert.php │ ├── SPUserNotice.php │ ├── IssuerSerial.php │ ├── NoticeRef.php │ ├── CRLRef.php │ ├── OCSPRef.php │ ├── Identifier.php │ ├── Transform.php │ ├── TransformXPath.php │ ├── SignerRole.php │ └── CRLIdentifier.php ├── SignedDocumentResourceInfo.php ├── BaseInputResourceInfo.php ├── Utils │ └── XPath.php └── InputResourceInfo.php ├── composer.json ├── autoload.php └── LICENSE /src/XAdESException.php: -------------------------------------------------------------------------------- 1 | . 5 | * All rights reserved. 6 | */ 7 | 8 | namespace lyquidity\xmldsig; 9 | 10 | class XAdESException extends \Exception 11 | {} -------------------------------------------------------------------------------- /src/KeyResourceInfo.php: -------------------------------------------------------------------------------- 1 | . 4 | * All rights reserved. 5 | * 6 | * GPL 3.0 7 | */ 8 | 9 | namespace lyquidity\xmldsig; 10 | 11 | /** 12 | * Records information about to data to be signed. 13 | */ 14 | class KeyResourceInfo extends ResourceInfo 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/CertificateResourceInfo.php: -------------------------------------------------------------------------------- 1 | . 4 | * All rights reserved. 5 | * 6 | * GPL 3.0 7 | */ 8 | 9 | namespace lyquidity\xmldsig; 10 | 11 | /** 12 | * Records information about to data to be signed. 13 | */ 14 | class CertificateResourceInfo extends ResourceInfo 15 | { 16 | 17 | } -------------------------------------------------------------------------------- /src/xml/SignaturePolicyBase.php: -------------------------------------------------------------------------------- 1 | = 7.2.6", 25 | "ext-openssl": "*", 26 | "lyquidity/requester": "*" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/xml/SignaturePolicyImplied.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | 17 | /** 18 | * Creates a node for <SignedAssertion> 19 | */ 20 | class SignedAssertion extends TextBase 21 | { 22 | /** 23 | * Returns the instance local name 24 | * @return string 25 | */ 26 | public function getLocalName() 27 | { 28 | return ElementNames::SignedAssertion; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /autoload.php: -------------------------------------------------------------------------------- 1 | 'xml/XmlClasses' ); 12 | if ( ! isset( $classes[ $filename ] ) ) return false; 13 | $filename = $classes[ $filename ]; 14 | if ( ! file_exists( __DIR__ . "/src/$filename.php" ) ) return false; 15 | } 16 | require_once __DIR__ . "/src/$filename.php"; 17 | } 18 | 19 | spl_autoload_register( 'xml_signer_autoload' ); 20 | -------------------------------------------------------------------------------- /src/xml/SPURI.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <SPURI> 21 | */ 22 | class SPURI extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::SPURI; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/DocumentationReference.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | 17 | /** 18 | * Creates a node for <DocumentationReference> 19 | */ 20 | class DocumentationReference extends TextBase 21 | { 22 | /** 23 | * Returns the instance local name 24 | * @return string 25 | */ 26 | public function getLocalName() 27 | { 28 | return ElementNames::DocumentationReference; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/xml/City.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <City> 21 | */ 22 | class City extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::City; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/Description.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <Description> 21 | */ 22 | class Description extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::Description; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/MimeType.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <MimeType> 21 | */ 22 | class MimeType extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::MimeType; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/PostalCode.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <PostalCode> 21 | */ 22 | class PostalCode extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::PostalCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/ClaimedRole.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <ClaimedRole> 21 | */ 22 | class ClaimedRole extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::ClaimedRole; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/CountryName.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <CountryName> 21 | */ 22 | class CountryName extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::CountryName; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/ExplicitText.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <ExplicitText> 21 | */ 22 | class ExplicitText extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::ExplicitText; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/Organization.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <Organization> 21 | */ 22 | class Organization extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::Organization; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/SigPolicyId.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <SigPolicyId> 21 | */ 22 | class SigPolicyId extends ObjectIdentifier 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::SigPolicyId; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/xml/StreetAddress.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <StreetAddress> 21 | */ 22 | class StreetAddress extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::StreetAddress; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/SigPolDocLocalURI.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <SigPolDocLocalURI> 21 | */ 22 | class SigPolDocLocalURI extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::SigPolDocLocalURI; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/ObjectReference.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <ObjectReference> 21 | */ 22 | class ObjectReference extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::ObjectReference; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/StateOrProvince.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <StateOrProvince> 21 | */ 22 | class StateOrProvince extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::StateOrProvince; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/IssuerSerialV2.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <IssuerSerialV2> 21 | */ 22 | class IssuerSerialV2 extends Base64String 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::IssuerSerialV2; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/OtherValue.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | */ 20 | 21 | /** 22 | * Creates a node for <OtherValue> 23 | */ 24 | class OtherValue extends XmlCore 25 | { 26 | /** 27 | * Returns the instance local name 28 | * @return string 29 | */ 30 | public function getLocalName() 31 | { 32 | return ElementNames::OtherValue; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/xml/SPDocSpecification.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <SPDocSpecification> 21 | */ 22 | class SPDocSpecification extends ObjectIdentifier 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::SPDocSpecification; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/AttributeNames.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <SignaturePolicyDocument> 21 | */ 22 | class SignaturePolicyDocument extends Base64String 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::SignaturePolicyDocument; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/CommitmentTypeQualifier.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <CommitmentTypeQualifier> 21 | */ 22 | class CommitmentTypeQualifier extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::CommitmentTypeQualifier; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/OtherAttributeCertificate.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <OtherAttributeCertificate> 21 | */ 22 | class OtherAttributeCertificate extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::OtherAttributeCertificate; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/EncapsulatedTimeStamp.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <EncapsulatedX509Certificate> 21 | */ 22 | class EncapsulatedTimeStamp extends EncapsulatedPKIData 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::EncapsulatedTimeStamp; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/RefsOnlyTimeStamp.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * This is a placeholder for this element which is not supported yet 21 | */ 22 | class RefsOnlyTimeStamp extends XmlCore implements UnsignedSignatureProperty 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::RefsOnlyTimeStamp; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/SigAndRefsTimeStamp.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * This is a placeholder for this element which is not supported yet 21 | */ 22 | class SigAndRefsTimeStamp extends XmlCore implements UnsignedSignatureProperty 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::SigAndRefsTimeStamp; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/EncapsulatedCRLValue.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | */ 20 | 21 | /** 22 | * Creates a node for <EncapsulatedCRLValue> 23 | */ 24 | class EncapsulatedCRLValue extends EncapsulatedPKIData 25 | { 26 | /** 27 | * Returns the instance local name 28 | * @return string 29 | */ 30 | public function getLocalName() 31 | { 32 | return ElementNames::EncapsulatedCRLValue; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/xml/EncapsulatedX509Certificate.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <EncapsulatedX509Certificate> 21 | */ 22 | class EncapsulatedX509Certificate extends EncapsulatedPKIData 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::EncapsulatedX509Certificate; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/EncapsulatedOCSPValue.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | */ 20 | 21 | /** 22 | * Creates a node for <EncapsulatedOCSPValue> 23 | */ 24 | class EncapsulatedOCSPValue extends EncapsulatedPKIData 25 | { 26 | /** 27 | * Returns the instance local name 28 | * @return string 29 | */ 30 | public function getLocalName() 31 | { 32 | return ElementNames::EncapsulatedOCSPValue; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/xml/IndividualDataObjectsTimeStamp.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <IndividualDataObjectsTimeStamp> 21 | */ 22 | class IndividualDataObjectsTimeStamp extends XAdESTimeStamp 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::IndividualDataObjectsTimeStamp; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/AttributeRevocationRefs.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <Description> 21 | */ 22 | class AttributeRevocationRefs extends CompleteRevocationRefs implements UnsignedSignatureProperty 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::AttributeRevocationRefs; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/AttrAuthoritiesCertValues.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <AttrAuthoritiesCertValues> 21 | */ 22 | class AttrAuthoritiesCertValues extends CertificateValues implements UnsignedSignatureProperty 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::AttrAuthoritiesCertValues; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/AttributeRevocationValues.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <AttributeRevocationValues> 21 | */ 22 | class AttributeRevocationValues extends RevocationValues implements UnsignedSignatureProperty 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::AttributeRevocationValues; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/xml/CommitmentTypeId.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <CommitmentTypeId> 21 | * This is just a proxy for ObjectIdentifier 22 | * which implements ObjectIdentifierType 23 | */ 24 | class CommitmentTypeId extends ObjectIdentifier 25 | { 26 | /** 27 | * Returns the instance local name 28 | * @return string 29 | */ 30 | public function getLocalName() 31 | { 32 | return ElementNames::CommitmentTypeId; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/xml/AttributeCertificateRefs.php: -------------------------------------------------------------------------------- 1 | 16 | * 17 | * 18 | */ 19 | 20 | /** 21 | * Creates a node for <CompleteCertificateRefs> 22 | */ 23 | class AttributeCertificateRefs extends CompleteCertificateRefs implements UnsignedSignatureProperty 24 | { 25 | /** 26 | * Returns the instance local name 27 | * @return string 28 | */ 29 | public function getLocalName() 30 | { 31 | return ElementNames::AttributeCertificateRefs; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/xml/AllSignedDataObjects.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <AllSignedDataObjects> 21 | * This element is just a flag to be used 'empty' so there are no properties 22 | * and just the XmlCore behaviour will be used 23 | */ 24 | class AllSignedDataObjects extends XmlCore 25 | { 26 | /** 27 | * Returns the instance local name 28 | * @return string 29 | */ 30 | public function getLocalName() 31 | { 32 | return ElementNames::AllSignedDataObjects; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/xml/SigningTime.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | class SigningTime extends TextBase 17 | { 18 | /** 19 | * Record the signing data. By default the value is now using the ISO 8601 date format. 20 | * 21 | * @param string $date 22 | */ 23 | public function __construct( $date = null ) 24 | { 25 | $this->text = $date ?? ( date_default_timezone_get() == 'UTC' ? date('Y-m-d\TH:i:s\Z') : date( 'c' ) ); //Do not use DateTime::ISO8601 26 | } 27 | 28 | /** 29 | * Returns the instance local name 30 | * @return string 31 | */ 32 | public function getLocalName() 33 | { 34 | return ElementNames::SigningTime; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/xml/CertDigest.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <CertDigest> 28 | */ 29 | class CertDigest extends DigestAlgAndValue 30 | { 31 | /** 32 | * Returns the instance local name 33 | * @return string 34 | */ 35 | public function getLocalName() 36 | { 37 | return ElementNames::CertDigest; 38 | } 39 | } -------------------------------------------------------------------------------- /src/xml/Integer.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <Int> 21 | */ 22 | class Integer extends TextBase 23 | { 24 | /** 25 | * Returns the instance local name 26 | * @return string 27 | */ 28 | public function getLocalName() 29 | { 30 | return ElementNames::Int; 31 | } 32 | 33 | /** 34 | * Allow the integer to be validated 35 | * @return void 36 | * @throws \Exception 37 | */ 38 | public function validateElement() 39 | { 40 | parent::validateElement(); 41 | 42 | if ( is_integer( $this->text ) ) return; 43 | 44 | throw new \Exception(" must be integer"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/xml/X509IssuerName.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | */ 20 | 21 | /** 22 | * Creates a node for <X509IssuerName> 23 | */ 24 | class X509IssuerName extends TextBase 25 | { 26 | /** 27 | * Create an instance with text 28 | * @param string $issuerName 29 | */ 30 | public function __construct( $issuerName = null ) 31 | { 32 | $this->defaultNamespace = XMLSecurityDSig::XMLDSIGNS; 33 | parent::__construct( $issuerName ); 34 | } 35 | 36 | /** 37 | * Returns the instance local name 38 | * @return string 39 | */ 40 | public function getLocalName() 41 | { 42 | return ElementNames::X509IssuerName; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/xml/AttributeCertificateRefsV2.php: -------------------------------------------------------------------------------- 1 | 19 | * 20 | */ 21 | 22 | /** 23 | * Creates a node for <AttributeCertificateRefsV2> 24 | */ 25 | class AttributeCertificateRefsV2 extends XmlCore 26 | { 27 | /** 28 | * Returns the instance local name 29 | * @return string 30 | */ 31 | public function getLocalName() 32 | { 33 | return ElementNames::AttributeCertificateRefsV2; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/xml/RefsOnlyTimeStampV2.php: -------------------------------------------------------------------------------- 1 | 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Placeholder for <RefsOnlyTimeStampV2> which is not supported yet 27 | */ 28 | class RefsOnlyTimeStampV2 extends XAdESTimeStamp 29 | { 30 | /** 31 | * Returns the instance local name 32 | * @return string 33 | */ 34 | public function getLocalName() 35 | { 36 | return ElementNames::RefsOnlyTimeStampV2; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/xml/X509SerialNumber.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | */ 20 | 21 | /** 22 | * Creates a node for <X509SerialNumber> 23 | */ 24 | class X509SerialNumber extends TextBase 25 | { 26 | /** 27 | * Create an instance with text 28 | * @param string $algorithm 29 | */ 30 | public function __construct( $serialNumber = null ) 31 | { 32 | $this->defaultNamespace = XMLSecurityDSig::XMLDSIGNS; 33 | parent::__construct( $serialNumber ); 34 | } 35 | 36 | /** 37 | * Returns the instance local name 38 | * @return string 39 | */ 40 | public function getLocalName() 41 | { 42 | return ElementNames::X509SerialNumber; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/xml/X509Certificate.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | */ 20 | 21 | /** 22 | * Creates a node for <X509Certificate> 23 | */ 24 | class X509Certificate extends Base64String 25 | { 26 | /** 27 | * Base 64 encoded PKI certificate 28 | * @param string $certificate 29 | */ 30 | public function __construct( $certificate = null ) 31 | { 32 | $this->defaultNamespace = XMLSecurityDSig::XMLDSIGNS; 33 | parent::__construct( $certificate ); 34 | } 35 | 36 | /** 37 | * Returns the instance local name 38 | * @return string 39 | */ 40 | public function getLocalName() 41 | { 42 | return ElementNames::X509Certificate; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/xml/SigAndRefsTimeStampV2.php: -------------------------------------------------------------------------------- 1 | 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Placeholder for <SigAndRefsTimeStampV2> which is not supported yet 27 | */ 28 | class SigAndRefsTimeStampV2 extends XAdESTimeStamp 29 | { 30 | /** 31 | * Returns the instance local name 32 | * @return string 33 | */ 34 | public function getLocalName() 35 | { 36 | return ElementNames::SigAndRefsTimeStampV2; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/xml/ArchiveTimeStamp.php: -------------------------------------------------------------------------------- 1 | 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Placeholder for <ArchiveTimeStamp> which is not supported yet 27 | */ 28 | class ArchiveTimeStamp extends XAdESTimeStamp implements UnsignedSignatureProperty 29 | { 30 | /** 31 | * Returns the instance local name 32 | * @return string 33 | */ 34 | public function getLocalName() 35 | { 36 | return ElementNames::ArchiveTimeStamp; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/xml/SignatureTimeStamp.php: -------------------------------------------------------------------------------- 1 | 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Placeholder for <SignatureTimeStamp> which is not supported yet 27 | */ 28 | class SignatureTimeStamp extends XAdESTimeStamp implements UnsignedSignatureProperty 29 | { 30 | /** 31 | * Returns the instance local name 32 | * @return string 33 | */ 34 | public function getLocalName() 35 | { 36 | return ElementNames::SignatureTimeStamp; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/xml/DigestValue.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Creates a node for <DigestValue> 27 | */ 28 | class DigestValue extends Base64String 29 | { 30 | /** 31 | * Create an instance with text 32 | * @param string $base64 33 | */ 34 | public function __construct( $base64 = null ) 35 | { 36 | $this->defaultNamespace = XMLSecurityDSig::XMLDSIGNS; 37 | parent::__construct( $base64 ); 38 | } 39 | 40 | /** 41 | * Returns the instance local name 42 | * @return string 43 | */ 44 | public function getLocalName() 45 | { 46 | return ElementNames::DigestValue; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/xml/CRLRefs.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Creates a node for <CRLRefs> 27 | */ 28 | class CRLRefs extends PropertiesCollection 29 | { 30 | /** 31 | * Create <CRLRef> 32 | * 33 | * @param CRLRef[]|CRLRef $crlRefs 34 | */ 35 | public function __construct( $crlRefs = null ) 36 | { 37 | parent::__construct( self::createConstructorArray( $crlRefs, CRLRef::class ) ); 38 | } 39 | 40 | /** 41 | * Returns the instance local name 42 | * @return string 43 | */ 44 | public function getLocalName() 45 | { 46 | return ElementNames::CRLRefs; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/xml/SigPolicyQualifier.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | 17 | /** 18 | * Creates a node for <SigPolicyQualifier> 19 | */ 20 | class SigPolicyQualifier extends Generic 21 | { 22 | /** 23 | * Constructor 24 | * 25 | * @param string|XmlCore $childNode 26 | */ 27 | public function __construct( $childNode = null ) 28 | { 29 | parent::__construct( $this->getLocalName() ); 30 | $this->childNodes = array(); 31 | $this->defaultNamespace = XmlCore::getDefaultNamespace(); 32 | 33 | if ( is_string( $childNode ) ) 34 | $this->text = $childNode; 35 | else if ( is_object( $childNode ) ) 36 | $this->addChildNode( $childNode ); 37 | } 38 | 39 | /** 40 | * Returns the instance local name 41 | * @return string 42 | */ 43 | public function getLocalName() 44 | { 45 | return ElementNames::SigPolicyQualifier; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/xml/XPathFilter.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | 19 | /** 20 | * Creates a node for <Transform> 21 | */ 22 | class XPathFilter extends TextBase 23 | { 24 | /** 25 | * Assign one of more <XPath> to this instance 26 | * 27 | * @param string $query 28 | * @param string[] $namespaces A set of namespaces used in the XPath query indexed by prefix 29 | */ 30 | public function __construct( $query = null, $namespaces = array() ) 31 | { 32 | $this->defaultNamespace = XMLSecurityDSig::XMLDSIGNS; 33 | // $this->query = $query; 34 | parent::__construct( $query ); 35 | if ( is_array( $namespaces ) ) 36 | $this->namespaces = $namespaces; 37 | } 38 | 39 | /** 40 | * Returns the instance local name 41 | * @return string 42 | */ 43 | public function getLocalName() 44 | { 45 | return ElementNames::XPath; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/xml/NoticeNumbers.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Creates a node for <NoticeNumbers> which is a list of integers 27 | */ 28 | class NoticeNumbers extends PropertiesCollection 29 | { 30 | /** 31 | * Create <CRLRef> 32 | * 33 | * @param Integer[]|Integer $integers 34 | */ 35 | public function __construct( $integers = null ) 36 | { 37 | parent::__construct( self::createConstructorArray( $integers, Integer::class ) ); 38 | } 39 | 40 | /** 41 | * Returns the instance local name 42 | * @return string 43 | */ 44 | public function getLocalName() 45 | { 46 | return ElementNames::NoticeNumbers; 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/xml/Encoding.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * The encoding value will usually be one of these URIs: 19 | * 20 | * http://uri.etsi.org/01903/v1.2.2#DER for denoting that the original PKI data were ASN.1 data encoded in DER. 21 | * http://uri.etsi.org/01903/v1.2.2#BER for denoting that the original PKI data were ASN.1 data encoded in BER. 22 | * http://uri.etsi.org/01903/v1.2.2#CER for denoting that the original PKI data were ASN.1 data encoded in CER. 23 | * http://uri.etsi.org/01903/v1.2.2#PER for denoting that the original PKI data were ASN.1 data encoded in PER. 24 | * http://uri.etsi.org/01903/v1.2.2#XER for denoting that the original PKI data were ASN.1 data encoded in XER 25 | */ 26 | 27 | /** 28 | * Creates a node for <Encoding> 29 | */ 30 | class Encoding extends TextBase 31 | { 32 | /** 33 | * Returns the instance local name 34 | * @return string 35 | */ 36 | public function getLocalName() 37 | { 38 | return ElementNames::Encoding; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/xml/CounterSignature.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <CounterSignature> 28 | */ 29 | class CounterSignature extends PropertiesCollection implements UnsignedSignatureProperty 30 | { 31 | /** 32 | * Create an instance of <CounterSignature> and pass in instances of <Signature> 33 | * @param Signature{}|Signature $signatures 34 | */ 35 | public function __construct( $signatures = null, $id = null ) 36 | { 37 | parent::__construct( self::createConstructorArray( $signatures, Signature::class ) ); 38 | $this->id = $id; 39 | } 40 | 41 | /** 42 | * Returns the instance local name 43 | * @return string 44 | */ 45 | public function getLocalName() 46 | { 47 | return ElementNames::CounterSignature; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/xml/CanonicalizationMethod.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | */ 28 | 29 | /** 30 | * Creates a node for <CanonicalizationMethod> 31 | */ 32 | class CanonicalizationMethod extends DigestMethod 33 | { 34 | /** 35 | * Provides a ready made instance for C14N 36 | * @var CanonicalizationMethod 37 | */ 38 | public static $defaultMethod; 39 | 40 | /** 41 | * Returns the instance local name 42 | * @return string 43 | */ 44 | public function getLocalName() 45 | { 46 | return ElementNames::CanonicalizationMethod; 47 | } 48 | } 49 | 50 | CanonicalizationMethod::$defaultMethod = new CanonicalizationMethod( XMLSecurityDSig::C14N ); -------------------------------------------------------------------------------- /src/xml/CertifiedRole.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * reates a node for <CertifiedRoles> which contains one or more <CertifiedRole> 29 | */ 30 | class CertifiedRole extends Base64String 31 | { 32 | /** 33 | * Creates an CertifiedRole instance 34 | * @param string $base64 This is a base 64 encoded binary of a DER encoded certificate 35 | * @param string $id (optional) 36 | */ 37 | public function __construct( $base64 = null, $id = null ) 38 | { 39 | $this->id = $id; 40 | parent::__construct( $base64 ); 41 | } 42 | 43 | /** 44 | * Returns the instance local name 45 | * @return string 46 | */ 47 | public function getLocalName() 48 | { 49 | return ElementNames::CertifiedRole; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/xml/SignatureMethod.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <Description> 29 | */ 30 | class SignatureMethod extends DigestMethod 31 | { 32 | /** 33 | * Provides an instance for SHA256 34 | * @var SignatureMethod 35 | * A static method of this name exists in the ancestor but is repeated 36 | * so each class can have its own default method type 37 | */ 38 | public static $defaultMethod; 39 | 40 | /** 41 | * Returns the instance local name 42 | * @return string 43 | */ 44 | public function getLocalName() 45 | { 46 | return ElementNames::SignatureMethod; 47 | } 48 | } 49 | 50 | SignatureMethod::$defaultMethod = new SignatureMethod( XMLSecurityDSig::SHA256 ); -------------------------------------------------------------------------------- /src/xml/OtherRef.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <OtherRef> 21 | */ 22 | class OtherRef extends Generic 23 | { 24 | /** 25 | * Allow a user to pass in the objects for which elements are to be created 26 | * Would be nice to used named parameters here but that ties the code v8.0 27 | * @param string $localName 28 | * @param string $prefix 29 | * @param string $namespace 30 | * @param string[] $attributes 31 | * @param XmlCore[] $childNodes 32 | * @param bool $preserveWhitespace (optional default false) 33 | */ 34 | public function __construct( $localName = null, $prefix = null, $namespace = null, $attributes = null, $childNodes = null, $preserveWhitespace = false ) 35 | { 36 | parent::__construct( $localName ?? $this->getLocalName(), $prefix, $namespace, $attributes, $childNodes, $preserveWhitespace ); 37 | } 38 | 39 | /** 40 | * Returns the instance local name 41 | * @return string 42 | */ 43 | public function getLocalName() 44 | { 45 | return ElementNames::OtherRef; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/xml/X509AttributeCertificate.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <Description> 29 | */ 30 | class X509AttributeCertificate extends Base64String 31 | { 32 | /** 33 | * Creates an X509AttributeCertificate instance 34 | * @param string $base64 This is a base 64 encoded binary of a DER encoded certificate 35 | * @param string $id (optional) 36 | */ 37 | public function __construct( $base64 = null, $id = null ) 38 | { 39 | $this->id = $id; 40 | parent::__construct( $base64 ); 41 | } 42 | 43 | /** 44 | * Returns the instance local name 45 | * @return string 46 | */ 47 | public function getLocalName() 48 | { 49 | return ElementNames::X509AttributeCertificate; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/xml/AllDataObjectsTimeStamp.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <AllDataObjectsTimeStamp> 21 | */ 22 | class AllDataObjectsTimeStamp extends XAdESTimeStamp 23 | { 24 | /** 25 | * When this element is used, the implicit mechanism will be used to compute and verify 26 | * Because of this, the Include element is not needed. 27 | * @param CanonicalizationMethod $canonicalizationMethod 28 | * @param EncapsulatedPKIData $encapsulatedTimeStamp 29 | * @param XMLTimeStamp $xmlTimestamp 30 | * @param string $id 31 | */ 32 | public function __construct( 33 | $canonicalizationMethod = null, 34 | $encapsulatedTimeStamp = null, 35 | $xmlTimestamp = null, 36 | $id = null ) 37 | { 38 | parent::__construct( null, $canonicalizationMethod, $encapsulatedTimeStamp, $xmlTimestamp, $id ); 39 | } 40 | 41 | /** 42 | * Returns the instance local name 43 | * @return string 44 | */ 45 | public function getLocalName() 46 | { 47 | return ElementNames::AllDataObjectsTimeStamp; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/xml/XMLTimeStamp.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <XMLTimeStamp> 21 | */ 22 | class XMLTimeStamp extends Generic 23 | { 24 | /** 25 | * Allow a user to pass in the objects for which elements are to be created 26 | * Would be nice to used named parameters here but that ties the code v8.0 27 | * @param string $localName 28 | * @param string $prefix 29 | * @param string $namespace 30 | * @param string[] $attributes 31 | * @param XmlCore[] $childNodes 32 | * @param bool $preserveWhitespace (optional default false) 33 | */ 34 | public function __construct( $localName = null, $prefix = null, $namespace = null, $attributes = null, $childNodes = null, $preserveWhitespace = false ) 35 | { 36 | parent::__construct( $localName ?? $this->getLocalName(), $prefix, $namespace, $attributes, $childNodes, $preserveWhitespace ); 37 | } 38 | 39 | /** 40 | * Returns the instance local name 41 | * @return string 42 | */ 43 | public function getLocalName() 44 | { 45 | return ElementNames::XMLTimeStamp; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/xml/OtherCertificate.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | */ 18 | 19 | /** 20 | * Creates a node for <OtherCertificate> 21 | */ 22 | class OtherCertificate extends Generic 23 | { 24 | 25 | /** 26 | * Allow a user to pass in the objects for which elements are to be created 27 | * Would be nice to used named parameters here but that ties the code v8.0 28 | * @param string $localName 29 | * @param string $prefix 30 | * @param string $namespace 31 | * @param string[] $attributes 32 | * @param XmlCore[] $childNodes 33 | * @param bool $preserveWhitespace (optional default false) 34 | */ 35 | public function __construct( $localName = null, $prefix = null, $namespace = null, $attributes = null, $childNodes = null, $preserveWhitespace = false ) 36 | { 37 | parent::__construct( $localName ?? $this->getLocalName(), $prefix, $namespace, $attributes, $childNodes, $preserveWhitespace ); 38 | } 39 | 40 | /** 41 | * Returns the instance local name 42 | * @return string 43 | */ 44 | public function getLocalName() 45 | { 46 | return ElementNames::OtherCertificate; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/xml/SignatureValue.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | */ 28 | 29 | /** 30 | * reates a node for <SignatureValues> which contains one or more <SignatureValue> 31 | */ 32 | class SignatureValue extends Base64String 33 | { 34 | /** 35 | * Creates an SignatureValue instance 36 | * @param string $base64 This is a base 64 encoded binary of a DER encoded certificate 37 | * @param string $id (optional) 38 | */ 39 | public function __construct( $base64 = null, $id = null ) 40 | { 41 | $this->defaultNamespace = XMLSecurityDSig::XMLDSIGNS; 42 | 43 | $this->id = $id; 44 | parent::__construct( $base64 ); 45 | } 46 | 47 | /** 48 | * Returns the instance local name 49 | * @return string 50 | */ 51 | public function getLocalName() 52 | { 53 | return ElementNames::SignatureValue; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/SignedDocumentResourceInfo.php: -------------------------------------------------------------------------------- 1 | . 4 | * All rights reserved. 5 | * 6 | * GPL 3.0 7 | */ 8 | 9 | namespace lyquidity\xmldsig; 10 | 11 | /** 12 | * Records information about to data to be signed. 13 | */ 14 | class SignedDocumentResourceInfo extends BaseInputResourceInfo 15 | { 16 | /** 17 | * If provided it will be the id if the signature to counter sign 18 | * @var string 19 | */ 20 | public $id = null; 21 | 22 | /** 23 | * This is an optional id that will be added to the counter signature to it is possible to counter sign the counter signature 24 | * @var string 25 | */ 26 | public $elementSignatureId = null; 27 | 28 | /** 29 | * Create signature resource descriptor 30 | * @param string $resource 31 | * @param int $type (optional: default = file) An or'd value of ResourceInfo::file ResourceInfo::binary ResourceInfo::des with ResourceInfo::base64 32 | * @param string $id (optional: default = true) 33 | * @param string $saveLocation (optional: default = file location) 34 | * @param string $saveFilename (optional: default = file name) 35 | * @param string $elementSignatureId 36 | */ 37 | public function __construct( $resource, $type = self::file, $id = null, $saveLocation = null, $saveFilename = null, $elementSignatureId = null ) 38 | { 39 | parent::__construct( $resource, $type, $saveLocation, $saveFilename ); 40 | $this->id = $id; 41 | $this->elementSignatureId = $elementSignatureId; 42 | } 43 | } -------------------------------------------------------------------------------- /src/xml/TextBase.php: -------------------------------------------------------------------------------- 1 | text = $text; 42 | } 43 | 44 | /** 45 | * Returns the text 46 | * @var string 47 | */ 48 | public function getValue() 49 | { 50 | return $this->text; 51 | } 52 | 53 | /** 54 | * Create a new Xml representation for $node 55 | * @param \DOMElement $node 56 | */ 57 | public function loadInnerXml($node) 58 | { 59 | parent::loadInnerXml( $node ); 60 | 61 | $this->text = $node->nodeValue; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2019, Robert Richards . 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | * Neither the name of Robert Richards nor the names of his 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /src/xml/OCSPRefs.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Creates a node for <OCSPRefs> 27 | */ 28 | class OCSPRefs extends PropertiesCollection 29 | { 30 | /** 31 | * Create <OCSPRef> 32 | * @param OCSPRef[]|OCSPRef $ocspRefs 33 | */ 34 | public function __construct( $ocspRefs = null ) 35 | { 36 | parent::__construct( self::createConstructorArray( $ocspRefs, OCSPRef::class ) ); 37 | } 38 | 39 | /** 40 | * Returns the instance local name 41 | * @return string 42 | */ 43 | public function getLocalName() 44 | { 45 | return ElementNames::OCSPRefs; 46 | } 47 | 48 | /** 49 | * Vaildate <OCSPRefs> and any descendent elements 50 | * @return void 51 | */ 52 | public function validateElement() 53 | { 54 | // Create a node for this element 55 | parent::validateElement(); 56 | 57 | $ocspRefs = $this->getPropertiesOfClass( OCSPRef::class ); 58 | if ( ! $ocspRefs ) 59 | throw new \Exception("There must be one or more OCSP ref if is used"); 60 | 61 | if ( count( $ocspRefs ) != count( $this->properties ) ) 62 | throw new \Exception("All children must be of type OCSPRef"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/xml/OtherRefs.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <OtherRefs> 29 | */ 30 | class OtherRefs extends PropertiesCollection 31 | { 32 | /** 33 | * Create <OtherRef> 34 | * 35 | * @param Generic[]|Generic $otherRefs 36 | */ 37 | public function __construct( $otherRefs = null ) 38 | { 39 | parent::__construct( self::createConstructorArray( $otherRefs, OtherRef::class ) ); 40 | } 41 | 42 | /** 43 | * Returns the instance local name 44 | * @return string 45 | */ 46 | public function getLocalName() 47 | { 48 | return ElementNames::OtherRefs; 49 | } 50 | 51 | /** 52 | * Vaildate <OtherRefs> and any descendent elements 53 | * @return void 54 | */ 55 | public function validateElement() 56 | { 57 | // Create a node for this element 58 | parent::validateElement(); 59 | 60 | $otherRefs = $this->getPropertiesOfClass( OtherRef::class ); 61 | if ( ! $otherRefs ) 62 | throw new \Exception("There must be one or more Other ref if is used"); 63 | 64 | if ( count( $otherRefs ) != count( $this->properties ) ) 65 | throw new \Exception("All children must be of type OtherRef"); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/xml/CertRefs.php: -------------------------------------------------------------------------------- 1 | 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <CertRefs> which contains one or more <Cert> 29 | */ 30 | class CertRefs extends PropertiesCollection 31 | { 32 | /** 33 | * Assign one of more <Cert> to this instance 34 | * 35 | * @param Cert|Cert[] $certRefs (optional) 36 | */ 37 | public function __construct( $certRefs = null ) 38 | { 39 | parent::__construct( self::createConstructorArray( $certRefs, Cert::class ) ); 40 | } 41 | 42 | /** 43 | * Returns the instance local name 44 | * @return string 45 | */ 46 | public function getLocalName() 47 | { 48 | return ElementNames::CertRefs; 49 | } 50 | 51 | /** 52 | * Validate all cert refs are CertRef instances 53 | * @return void 54 | * @throws \Exception 55 | */ 56 | public function validateElement() 57 | { 58 | parent::validateElement(); 59 | 60 | $certRefs = $this->getPropertiesOfClass( Cert::class ); 61 | if ( ! $certRefs ) 62 | throw new \Exception("There must be one or more instances if a is used"); 63 | 64 | if ( count( $certRefs ) != count( $this->properties ) ) 65 | throw new \Exception("All children must be of type Cert"); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/xml/ClaimedRoles.php: -------------------------------------------------------------------------------- 1 | 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <ClaimedRoles> which contains one or more <ClaimedRole> 28 | */ 29 | class ClaimedRoles extends PropertiesCollection 30 | { 31 | /** 32 | * Assign one of more <ClaimedRole> to this instance 33 | * @param ClaimedRole|ClaimedRole[]|string $claimedRoles (optional) 34 | */ 35 | public function __construct( $claimedRoles = null ) 36 | { 37 | parent::__construct( self::createConstructorArray( $claimedRoles, ClaimedRole::class ) ); 38 | } 39 | 40 | /** 41 | * Returns the instance local name 42 | * @return string 43 | */ 44 | public function getLocalName() 45 | { 46 | return ElementNames::ClaimedRoles; 47 | } 48 | 49 | /** 50 | * Validate all claimed roles are ClaimedRole instances 51 | * @return void 52 | * @throws \Exception 53 | */ 54 | public function validateElement() 55 | { 56 | parent::validateElement(); 57 | 58 | $claimedRoles = $this->getPropertiesOfClass( ClaimedRole::class ); 59 | if ( ! $claimedRoles ) 60 | throw new \Exception("There must be one or more claimed roles if a is used"); 61 | 62 | if ( count( $claimedRoles ) != count( $this->properties ) ) 63 | throw new \Exception("All children must be of type ClaimedRoles"); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/xml/CRLValues.php: -------------------------------------------------------------------------------- 1 | 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <CRLValues> which contains one or more <EncapsulatedCRLValue> 29 | */ 30 | class CRLValues extends PropertiesCollection 31 | { 32 | /** 33 | * Assign one of more <EncapsulatedCRLValue> to this instance 34 | * 35 | * @param EncapsulatedCRLValue|EncapsulatedCRLValue[]|string $encapsulatedCRLValues (optional) 36 | */ 37 | public function __construct( $encapsulatedCRLValues = null ) 38 | { 39 | parent::__construct( self::createConstructorArray( $encapsulatedCRLValues, EncapsulatedCRLValue::class ) ); 40 | } 41 | 42 | /** 43 | * Returns the instance local name 44 | * @return string 45 | */ 46 | public function getLocalName() 47 | { 48 | return ElementNames::CRLValues; 49 | } 50 | 51 | /** 52 | * Validate all values are CRLValues instances 53 | * @return void 54 | * @throws \Exception 55 | */ 56 | public function validateElement() 57 | { 58 | $encapsulatedCRLValues = $this->getPropertiesOfClass( EncapsulatedCRLValue::class ); 59 | 60 | if ( count( $encapsulatedCRLValues ) != count( $this->properties ) ) 61 | throw new \Exception("All children must be of type EncapsulatedCRLValue"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/xml/CertificateValues.php: -------------------------------------------------------------------------------- 1 | 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * /xsd:complexType> 26 | */ 27 | 28 | /** 29 | * Creates a node for <CertificateValues> 30 | */ 31 | class CertificateValues extends PropertiesCollection implements UnsignedSignatureProperty 32 | { 33 | /** 34 | * Create an instance of <CertificateValues> and pass in instances of <EncapsulatedX509Certificate>, <OtherCertificate> 35 | * @param EncapsulatedX509Certificate|EncapsulatedX509Certificate[] $encapsulatedX509Certificates 36 | * @param OtherCertificate|OtherCertificate[] $otherCertificates 37 | */ 38 | public function __construct( $encapsulatedX509Certificates = null, $otherCertificates = null, $id = null ) 39 | { 40 | parent::__construct( array_merge( 41 | self::createConstructorArray( $encapsulatedX509Certificates, EncapsulatedX509Certificate::class ) ?? array(), 42 | self::createConstructorArray( $otherCertificates, OtherCertificate::class ) ?? array() 43 | ) ); 44 | 45 | $this->id = $id; 46 | } 47 | 48 | /** 49 | * Returns the instance local name 50 | * @return string 51 | */ 52 | public function getLocalName() 53 | { 54 | return ElementNames::CertificateValues; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/xml/ReferenceInfo.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * xsd:sequence> 20 | * xsd:element ref="ds:DigestMethod"/> 21 | * xsd:element ref="ds:DigestValue"/> 22 | * /xsd:sequence> 23 | * xsd:attribute name="Id" type="xsd:ID" use="optional"/> 24 | * xsd:attribute name="URI" type="xsd:anyURI" use="optional"/> 25 | * 26 | */ 27 | 28 | /** 29 | * Creates a node for <ReferenceInfo> 30 | */ 31 | class ReferenceInfo extends CertDigest 32 | { 33 | /** 34 | * Represents @URI 35 | * @var string 36 | */ 37 | private $uri = null; 38 | 39 | /** 40 | * Returns the instance local name 41 | * @return string 42 | */ 43 | public function getLocalName() 44 | { 45 | return ElementNames::ReferenceInfo; 46 | } 47 | 48 | /** 49 | * Generate xml for the element and the attributes 50 | * 51 | * @param \DOMElement $parentNode 52 | * @param string[] $attributes 53 | * @param \DOMElement $insertAfter 54 | * @return \DOMElement 55 | */ 56 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 57 | { 58 | parent::generateXml( $parentNode, array( AttributeNames::Uri => $this->uri ), $insertAfter ); 59 | } 60 | 61 | /** 62 | * Load the elements and attributes 63 | * @param \DOMElement $node 64 | * @return ReferenceInfo 65 | */ 66 | public function loadInnerXml( $node ) 67 | { 68 | parent::loadInnerXml( $node ); 69 | 70 | $attr = $node->getAttributeNode( AttributeNames::Uri ); 71 | if ( $attr ) 72 | { 73 | $this->uri = $attr->value; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/xml/Base64String.php: -------------------------------------------------------------------------------- 1 | and <DigestValue>. 54 | * @throws \Exception 55 | */ 56 | public function validateElement() 57 | { 58 | parent::validateElement(); 59 | self::validateBase64String( $this->text ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/xml/CommitmentTypeQualifiers.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Creates a node for <CommitmentTypeQualifiers> 27 | */ 28 | class CommitmentTypeQualifiers extends PropertiesCollection 29 | { 30 | /** 31 | * Assign one of more CommitmentTypeQualifier to this instance 32 | * @param CommitmentTypeQualifier|CommitmentTypeQualifier[]|string $commitmentTypeQualifiers 33 | */ 34 | public function __construct( $commitmentTypeQualifiers = null ) 35 | { 36 | parent::__construct( self::createConstructorArray( $commitmentTypeQualifiers, CommitmentTypeQualifier::class ) ); 37 | } 38 | 39 | /** 40 | * Returns the instance local name 41 | * @return string 42 | */ 43 | public function getLocalName() 44 | { 45 | return ElementNames::CommitmentTypeQualifiers; 46 | } 47 | 48 | /** 49 | * Validate all Commitment Type Qualifiers are CommitmentTypeQualifier instances 50 | * @return void 51 | * @throws \Exception 52 | */ 53 | public function validateElement() 54 | { 55 | parent::validateElement(); 56 | 57 | $commitmentTypeQualifiers = $this->getPropertiesOfClass( CommitmentTypeQualifier::class ); 58 | 59 | if ( count( $commitmentTypeQualifiers ) != count( $this->properties ) ) 60 | throw new \Exception("All children must be of type CommitmentTypeQualifier"); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/xml/DocumentationReferences.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Creates a node for <DocumentationReferences> 27 | */ 28 | class DocumentationReferences extends PropertiesCollection 29 | { 30 | /** 31 | * Assign one of more references to this instance 32 | * @param DocumentationReference|DocumentationReference[]|string $references 33 | */ 34 | public function __construct( $references = null ) 35 | { 36 | parent::__construct( self::createConstructorArray( $references, DocumentationReference::class ) ); 37 | } 38 | 39 | /** 40 | * Returns the instance local name 41 | * @return string 42 | */ 43 | public function getLocalName() 44 | { 45 | return ElementNames::DocumentationReferences; 46 | } 47 | 48 | /** 49 | * Vaildate <DocumentationReferences> and any descendent elements 50 | * @return void 51 | */ 52 | public function validateElement() 53 | { 54 | // Create a node for this element 55 | parent::validateElement(); 56 | 57 | $documentationReferences = $this->getPropertiesOfClass( DocumentationReference::class ); 58 | if ( ! $documentationReferences ) 59 | throw new \Exception("There must be one or more Documentation Reference if is used"); 60 | 61 | if ( count( $documentationReferences ) != count( $this->properties ) ) 62 | throw new \Exception("All children must be of type DocumentationReference"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/xml/OCSPValues.php: -------------------------------------------------------------------------------- 1 | 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <OCSPValues> which contains one or more <EncapsulatedOCSPValue> 29 | */ 30 | class OCSPValues extends PropertiesCollection 31 | { 32 | /** 33 | * Assign one of more <EncapsulatedOCSPValue> to this instance 34 | * 35 | * @param EncapsulatedOCSPValue|EncapsulatedOCSPValue[]|string $encapsulatedOCSPValues (optional) 36 | */ 37 | public function __construct( $encapsulatedOCSPValues = null ) 38 | { 39 | parent::__construct( self::createConstructorArray( $encapsulatedOCSPValues, EncapsulatedOCSPValue::class ) ); 40 | } 41 | 42 | /** 43 | * Returns the instance local name 44 | * @return string 45 | */ 46 | public function getLocalName() 47 | { 48 | return ElementNames::OCSPValues; 49 | } 50 | 51 | /** 52 | * Validate all values are OCSPValues instances 53 | * @return void 54 | * @throws \Exception 55 | */ 56 | public function validateElement() 57 | { 58 | // Create a node for this element 59 | parent::validateElement(); 60 | 61 | $ocspValues = $this->getPropertiesOfClass( EncapsulatedOCSPValue::class ); 62 | if ( ! $ocspValues ) 63 | throw new \Exception("There must be one or more EncapsulatedOCSPValue if is used"); 64 | 65 | if ( count( $ocspValues ) != count( $this->properties ) ) 66 | throw new \Exception("All children must be of type EncapsulatedOCSPValue"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/xml/OtherValues.php: -------------------------------------------------------------------------------- 1 | 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <OtherValues> which contains one or more <OtherValue> 29 | */ 30 | class OtherValues extends PropertiesCollection 31 | { 32 | /** 33 | * Represents a collection of <OtherValue> 34 | * @var OtherValue[] 35 | */ 36 | public $otherValues = array(); 37 | 38 | /** 39 | * Assign one of more <OtherValue> to this instance 40 | * 41 | * @param OtherValue|OtherValue[]|string $otherValues (optional) 42 | */ 43 | public function __construct( $otherValues = null ) 44 | { 45 | parent::__construct( self::createConstructorArray( $otherValues, OtherValue::class ) ); 46 | } 47 | 48 | /** 49 | * Returns the instance local name 50 | * @return string 51 | */ 52 | public function getLocalName() 53 | { 54 | return ElementNames::OtherValues; 55 | } 56 | 57 | 58 | /** 59 | * Validate all values are OtherValues instances 60 | * @return void 61 | * @throws \Exception 62 | */ 63 | public function validateElement() 64 | { 65 | // Create a node for this element 66 | parent::validateElement(); 67 | 68 | $otherValues = $this->getPropertiesOfClass( OtherValue::class ); 69 | if ( ! $otherValues ) 70 | throw new \Exception("There must be one or more OtherValue if is used"); 71 | 72 | if ( count( $otherValues ) != count( $this->properties ) ) 73 | throw new \Exception("All children must be of type OtherValue"); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/xml/SignedAssertions.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <SignedAssertions> 29 | */ 30 | class SignedAssertions extends PropertiesCollection 31 | { 32 | /** 33 | * A collection of assertions 34 | * @var SignedAssertion[] 35 | */ 36 | public $assertions = array(); 37 | 38 | /** 39 | * Assign one of more assertions to this instance 40 | * 41 | * @param SignedAssertion|SignedAssertion[]|string $assertions 42 | */ 43 | public function __construct( $assertions = null ) 44 | { 45 | parent::__construct( self::createConstructorArray( $assertions, SignedAssertion::class ) ); 46 | } 47 | 48 | /** 49 | * Returns the instance local name 50 | * @return string 51 | */ 52 | public function getLocalName() 53 | { 54 | return ElementNames::SignedAssertions; 55 | } 56 | 57 | /** 58 | * Validate all assertions are SignedAssertion instances 59 | * @return void 60 | * @throws \Exception 61 | */ 62 | public function validateElement() 63 | { 64 | // Create a node for this element 65 | parent::validateElement(); 66 | 67 | $signedAssertion = $this->getPropertiesOfClass( SignedAssertion::class ); 68 | if ( ! $signedAssertion ) 69 | throw new \Exception("There must be one or more SignedAssertion if is used"); 70 | 71 | if ( count( $signedAssertion ) != count( $this->properties ) ) 72 | throw new \Exception("All children must be of type SignedAssertion"); } 73 | } 74 | -------------------------------------------------------------------------------- /src/xml/CertRefsV2.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | */ 32 | 33 | /** 34 | * Creates a node for <CertRefsV2> which contains one or more <Cert> 35 | */ 36 | class CertRefsV2 extends PropertiesCollection 37 | { 38 | /** 39 | * Assign one of more <Cert> to this instance 40 | * 41 | * @param CertV2|CertV2[] $certRefs (optional) 42 | */ 43 | public function __construct( $certRefs = null ) 44 | { 45 | if ( ! $certRefs ) return; 46 | parent::__construct( 47 | self::createConstructorArray( $certRefs, CertV2::class ), 48 | array( ElementNames::Cert => basename( CertV2::class ) ) 49 | ); 50 | } 51 | 52 | /** 53 | * Returns the instance local name 54 | * @return string 55 | */ 56 | public function getLocalName() 57 | { 58 | return ElementNames::CertRefs; 59 | } 60 | 61 | /** 62 | * Validate all cert refs are CertRef instances 63 | * @return void 64 | * @throws \Exception 65 | */ 66 | public function validateElement() 67 | { 68 | parent::validateElement(); 69 | 70 | $certRefs = $this->getPropertiesOfClass( CertV2::class ); 71 | if ( ! $certRefs ) 72 | throw new \Exception("There must be one or more instances if a is used"); 73 | 74 | if ( count( $certRefs ) != count( $this->properties ) ) 75 | throw new \Exception("All children must be of type Cert"); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/xml/CertifiedRoles.php: -------------------------------------------------------------------------------- 1 | 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | 35 | /** 36 | * Creates a node for <CertifiedRoles> which contains one or more <CertifiedRole> 37 | */ 38 | class CertifiedRoles extends PropertiesCollection 39 | { 40 | /** 41 | * Assign one of more <CertifiedRole> to this instance 42 | * 43 | * @param CertifiedRole|CertifiedRole[]|string $certifiedRoles (optional) 44 | */ 45 | public function __construct( $certifiedRoles = null ) 46 | { 47 | parent::__construct( self::createConstructorArray( $certifiedRoles, CertifiedRole::class ) ); 48 | } 49 | 50 | /** 51 | * Returns the instance local name 52 | * @return string 53 | */ 54 | public function getLocalName() 55 | { 56 | return ElementNames::CertifiedRoles; 57 | } 58 | 59 | /** 60 | * Validate all references are CertifiedRole instances 61 | * @return void 62 | * @throws \Exception 63 | */ 64 | public function validateElement() 65 | { 66 | parent::validateElement(); 67 | 68 | $certifiedRoles = $this->getPropertiesOfClass( CertifiedRole::class ); 69 | if ( ! $certifiedRoles ) 70 | throw new \Exception("There must be one or more certified roles if a is used"); 71 | 72 | if ( count( $certifiedRoles ) != count( $this->properties ) ) 73 | throw new \Exception("All children must be of type CertifiedRole"); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/xml/SigPolicyQualifiers.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /** 26 | * Creates a node for <SigPolicyQualifiers> 27 | */ 28 | class SigPolicyQualifiers extends PropertiesCollection 29 | { 30 | /** 31 | * Assign one of more references to this instance 32 | * 33 | * @param SigPolicyQualifier|SigPolicyQualifier[]|string $references 34 | */ 35 | public function __construct( $sigPolicyQualifiers = null ) 36 | { 37 | parent::__construct( self::createConstructorArray( $sigPolicyQualifiers, SigPolicyQualifier::class ) ); 38 | } 39 | 40 | /** 41 | * Returns the instance local name 42 | * @return string 43 | */ 44 | public function getLocalName() 45 | { 46 | return ElementNames::SigPolicyQualifiers; 47 | } 48 | 49 | /** 50 | * Validate all sigPolicyQualifiers are SigPolicyQualifier instances 51 | * @return void 52 | * @throws \Exception 53 | */ 54 | public function validateElement() 55 | { 56 | // Create a node for this element 57 | parent::validateElement(); 58 | 59 | $sigPolicyQualifiers = $this->getPropertiesOfClass( SigPolicyQualifier::class ); 60 | 61 | if ( count( $sigPolicyQualifiers ) != count( $this->properties ) ) 62 | throw new \Exception("All children must be of type SigPolicyQualifier"); 63 | } 64 | 65 | /** 66 | * Create <properties> and any descendent elements 67 | * 68 | * @param \DOMElement $parentNode 69 | * @param string[] $attributes 70 | * @param \DOMElement $insertAfter 71 | * @return \DOMElement 72 | */ 73 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 74 | { 75 | // Create a nodes for this element 76 | parent::generateXml( $parentNode, $attributes, $insertAfter ); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/xml/EncapsulatedPKIData.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * which contains one or more <EncapsulatedPKIData> 30 | */ 31 | class EncapsulatedPKIData extends Base64String 32 | { 33 | /** 34 | * Content of @Encoding 35 | * @var string 36 | */ 37 | public $encoding = 'http://uri.etsi.org/01903/v1.2.2#DER'; 38 | 39 | /** 40 | * Creates an EncapsulatedPKIData instance 41 | * @param string $base64 This is a base 64 encoded binary of a DER encoded certificate 42 | * @param string $id (optional) 43 | * @param Encoding $encoding (optional) Defaults to the DER URI 44 | */ 45 | public function __construct( $base64 = null, $id = null, $encoding = null ) 46 | { 47 | $this->id = $id; 48 | if ( ! is_null( $encoding ) ) 49 | $this->encoding = $encoding; 50 | parent::__construct( $base64 ); 51 | } 52 | 53 | /** 54 | * Returns the instance local name 55 | * @return string 56 | */ 57 | public function getLocalName() 58 | { 59 | return ElementNames::EncapsulatedPKIData; 60 | } 61 | 62 | /** 63 | * Create an element with an optional @Id 64 | * 65 | * @param \DOMElement $parentNode 66 | * @param string[] $attributes 67 | * @param \DOMElement $insertAfter 68 | * @return \DOMElement 69 | */ 70 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 71 | { 72 | return parent::generateXml( $parentNode, array( AttributeNames::Encoding => $this->encoding ), $insertAfter ); 73 | } 74 | 75 | /** 76 | * Create a new Xml representation for $node 77 | * @param \DOMElement $node 78 | */ 79 | public function loadInnerXml($node) 80 | { 81 | parent::loadInnerXml( $node ); 82 | 83 | $attr = $node->getAttributeNode( AttributeNames::Encoding ); 84 | if ( $attr ) 85 | $this->encoding = $attr->value; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/xml/CertifiedRolesV2.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | * 34 | * 35 | * 36 | * 37 | * 38 | * 39 | * 40 | * 41 | * 42 | * 43 | */ 44 | 45 | /** 46 | * Creates a node for <CertifiedRolesV2> which contains one or more <CertifiedRole> 47 | */ 48 | class CertifiedRolesV2 extends PropertiesCollection 49 | { 50 | /** 51 | * Assign one of more <CertifiedRoleV2> to this instance 52 | * 53 | * @param CertifiedRoleV2|CertifiedRoleV2[] $certifiedRolesV2 (optional) 54 | */ 55 | public function __construct( $certifiedRolesV2 = null ) 56 | { 57 | parent::__construct( 58 | self::createConstructorArray( $certifiedRolesV2, CertifiedRoleV2::class ), 59 | array( ElementNames::CertifiedRole => basename( CertifiedRoleV2::class ) ) 60 | ); 61 | } 62 | 63 | /** 64 | * Returns the instance local name 65 | * @return string 66 | */ 67 | public function getLocalName() 68 | { 69 | return ElementNames::CertifiedRolesV2; 70 | } 71 | 72 | /** 73 | * Validate all references are CertifiedRoleV2 instances 74 | * @return void 75 | * @throws \Exception 76 | */ 77 | public function validateElement() 78 | { 79 | parent::validateElement(); 80 | 81 | $certifiedRoles = $this->getPropertiesOfClass( CertifiedRoleV2::class ); 82 | if ( ! $certifiedRoles ) 83 | throw new \Exception("There must be one or more certified roles if a is used"); 84 | 85 | if ( count( $certifiedRoles ) != count( $this->properties ) ) 86 | throw new \Exception("All children must be of type CertifiedRoleV2"); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/xml/UnsignedDataObjectProperties.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <unsignedDataObjectProperties> which contains one or more arbitrary child nodes> 28 | */ 29 | class UnsignedDataObjectProperties extends XmlCore 30 | { 31 | /** 32 | * A set of nodes represented by a Generic array 33 | * 34 | * @var Generic[] 35 | */ 36 | public $unsignedDataObjectProperty; 37 | 38 | /** 39 | * Creates an UnsignedDataObjectProperties instance 40 | * @param Generic|Generic|string $content This is the subordinate content 41 | * @param string $id (optional) 42 | */ 43 | public function __construct( $content = null, $id = null ) 44 | { 45 | // if ( $content ) 46 | // throw new \Exception(" is not supported yet."); 47 | 48 | $this->unsignedDataObjectProperty = self::createConstructorArray( $content, Generic::class ); 49 | 50 | $this->id = $id; 51 | } 52 | 53 | /** 54 | * Returns the instance local name 55 | * @return string 56 | */ 57 | public function getLocalName() 58 | { 59 | return ElementNames::UnsignedDataObjectProperties; 60 | } 61 | 62 | /** 63 | * Create a <UnsignedDataObjectProperties 64 | * 65 | * @param \DOMElement $parentNode 66 | * @param string[] $attributes 67 | * @param \DOMElement $insertAfter 68 | * @return \DOMElement 69 | */ 70 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 71 | { 72 | parent::generateXml( $parentNode, $attributes, $insertAfter ); 73 | 74 | // TODO 75 | } 76 | 77 | /** 78 | * Calls the closure in $callback and does the same on any descendents 79 | * @param Closure $callback 80 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 81 | * @return XmlCore 82 | */ 83 | public function traverse( $callback, $depthFirst = false ) 84 | { 85 | if ( $callback instanceof \Closure ) 86 | { 87 | if ( ! $depthFirst ) 88 | parent::traverse( $callback, $depthFirst ); 89 | 90 | 91 | // TODO 92 | 93 | if ( $depthFirst ) 94 | parent::traverse( $callback, $depthFirst ); 95 | } 96 | return $this; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/xml/DigestMethod.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <DigestMethod> 29 | */ 30 | class DigestMethod extends XmlCore 31 | { 32 | /** 33 | * Provides an instance for SHA256 34 | * @var SignatureMethod 35 | */ 36 | public static $defaultMethod; 37 | 38 | /** 39 | * This will become an attribute @Algorithm with a restricted list 40 | * of legal values that are valid digest uris 41 | * @var string 42 | */ 43 | public $algorithm = XMLSecurityDSig::SHA256; 44 | 45 | /** 46 | * Create an instance with text 47 | * @param string $algorithm 48 | */ 49 | public function __construct( $algorithm = null ) 50 | { 51 | $this->defaultNamespace = XMLSecurityDSig::XMLDSIGNS; 52 | $this->algorithm = $algorithm; 53 | } 54 | 55 | /** 56 | * Returns the instance local name 57 | * @return string 58 | */ 59 | public function getLocalName() 60 | { 61 | return ElementNames::DigestMethod; 62 | } 63 | 64 | /** 65 | * Create <DigestMethod> and any descendent elements 66 | * 67 | * @param \DOMElement $parentNode 68 | * @param string[] $attributes 69 | * @param \DOMElement $insertAfter 70 | * @return \DOMElement 71 | */ 72 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 73 | { 74 | // Create a node for this element 75 | $newElement = parent::generateXml( $parentNode, array( AttributeNames::Algorithm => $this->algorithm ), $insertAfter ); 76 | } 77 | 78 | /** 79 | * Load the child elements of <SigPolicyQualifiers> 80 | * @param \DOMElement $node 81 | * @return DocumentationReference 82 | */ 83 | public function loadInnerXml( $node ) 84 | { 85 | parent::loadInnerXml( $node ); 86 | 87 | $attr = $node->getAttributeNode( AttributeNames::Algorithm ); 88 | if ( ! $attr ) return; 89 | $this->algorithm = $attr->value; 90 | } 91 | 92 | /** 93 | * Validate <DigestMethod>. 94 | * @throws \Exception 95 | */ 96 | public function validateElement() 97 | { 98 | // May need to check the algorithm is a valid one but first need a comprehensive list 99 | } 100 | } 101 | 102 | DigestMethod::$defaultMethod = new DigestMethod( XMLSecurityDSig::SHA256 ); -------------------------------------------------------------------------------- /src/xml/TransformXPathFilter2.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * * 26 | */ 27 | 28 | /** 29 | * Creates a node for <Transform> but where there are XPath-Filter 2 XPath nodes 30 | */ 31 | class TransformXPathFilter2 extends TransformXPath 32 | { 33 | /** 34 | * Assign one of more to this instance 35 | * @param XPathFilter2|XPathFilter2[]|string $xpaths 36 | */ 37 | public function __construct( $xpaths = null ) 38 | { 39 | Transform::__construct( XMLSecurityDSig::XPATH_FILTER2 ); 40 | if ( ! $xpaths ) return; 41 | 42 | // Check the xpaths are XPathFilter2 43 | if ( is_string( $xpaths ) ) 44 | { 45 | $this->xpaths[] = $this->createXPathInstance( $xpaths ); 46 | } 47 | else if ( $xpaths instanceof XPathFilter2 ) 48 | { 49 | $this->xpaths[] = $xpaths; 50 | } 51 | else if ( is_array( $xpaths ) ) 52 | { 53 | // Check all array members are XPathFilter2 54 | foreach( $xpaths as $xpath ) 55 | { 56 | if ( ! $xpath instanceof XPathFilter2 && ! is_string( $xpath ) ) 57 | throw new \Exception("All the members of the array passed to the TransformXPathFilter2 constructor must be of type XPathFilter2 or string"); 58 | $this->xpaths[] = $xpath instanceof XPathFilter ? $xpath : new XPathFilter2( $xpath ); 59 | } 60 | } 61 | else throw new \Exception("The XPaths parameter passed to the TransformXPathFilter2 constructor is not valid"); 62 | } 63 | 64 | /** 65 | * Generate the correct type of XPath class 66 | * @param string $query (optional) 67 | * @return XPathFilter 68 | */ 69 | protected function createXPathInstance( $query = null ) 70 | { 71 | return new XPathFilter2( $query ); 72 | } 73 | 74 | /** 75 | * Converts a transform to a simple representation representation for use by XMLSecurityDSig::AddRefInternal() 76 | * @return void 77 | */ 78 | public function toSimpleRepresentation() 79 | { 80 | return array( $this->algorithm => array( 81 | array_reduce( $this->xpaths, function( $carry, $xpath ) 82 | { 83 | /** @var XPathFilter2 $xpath */ 84 | $carry[] = array( 85 | 'query' => $xpath->text, 86 | 'namespaces' => $xpath->namespaces, 87 | 'filter' => $xpath->filter 88 | ); 89 | return $carry; 90 | }, array() ) 91 | ) ); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/BaseInputResourceInfo.php: -------------------------------------------------------------------------------- 1 | . 4 | * All rights reserved. 5 | * 6 | * GPL 3.0 7 | */ 8 | 9 | namespace lyquidity\xmldsig; 10 | 11 | /** 12 | * This is an abstract base class for all input XML documents 13 | */ 14 | abstract class BaseInputResourceInfo extends ResourceInfo 15 | { 16 | /** 17 | * An optional location (folder or dir) to save the signature file. 18 | * If this is not specified and the resource is a file location then 19 | * the signature will be saved in the same folder as the file. 20 | * If the resource is something else (DOMDOcument, URL, etc.) the 21 | * signature will be saved in the current folder. 22 | * @var string 23 | */ 24 | public $saveLocation = null; 25 | 26 | /** 27 | * (optional)The name of the file to save the output 28 | * @var string 29 | */ 30 | public $saveFilename = null; 31 | 32 | /** 33 | * Allows a caller to show the file is large so the LIBXML_PARSEHUGE flag will be used 34 | * This is not relevant for an existing DOM document 35 | */ 36 | public $hugeFile = false; 37 | 38 | /** 39 | * Create signature resource descriptor 40 | * @param string $resource 41 | * @param int $type (optional: default = file) An or'd value of ResourceInfo::file ResourceInfo::binary ResourceInfo::des with ResourceInfo::base64 42 | * @param string $saveLocation (optional: default = file location) 43 | * @param string $saveFilename (optional: default = file name) 44 | */ 45 | public function __construct( $resource, $type = self::file, $saveLocation = null, $saveFilename = null ) 46 | { 47 | parent::__construct( $resource, $type ); 48 | $this->saveLocation = $saveLocation; 49 | $this->saveFilename = $saveFilename; 50 | } 51 | 52 | /** 53 | * Generate dom document from resource data 54 | * @return \DOMDocument 55 | */ 56 | public function generateDomDocument() 57 | { 58 | if ( $this->isFile() ) 59 | { 60 | if (!file_exists($this->resource)) 61 | { 62 | throw new XAdESException("XML file does not exist"); 63 | } 64 | 65 | // Load the XML to be signed 66 | $doc = new \DOMDocument(); 67 | $doc->load( $this->resource, $this->hugeFile ? LIBXML_PARSEHUGE : 0 ); 68 | } 69 | else if ( $this->isXmlDocument() ) 70 | { 71 | $doc = clone( $this->resource ); 72 | } 73 | else if ( $this->isURL() ) 74 | { 75 | // Load the XML to be signed 76 | $doc = new \DOMDocument(); 77 | if ( ! $doc->load( $this->resource, $this->hugeFile ? LIBXML_PARSEHUGE : 0 ) ) 78 | { 79 | throw new XAdESException( "URL does not reference a valid XML document" ); 80 | } 81 | } 82 | else if ($this->isString()) 83 | { 84 | $doc = new \DOMDocument(); 85 | if ( ! $doc->loadXML( $this->resource, $this->hugeFile ? LIBXML_PARSEHUGE : 0 ) ) 86 | { 87 | throw new XAdESException( "Unable to load XML string" ); 88 | } 89 | } 90 | else 91 | { 92 | throw new XAdESException("The resource supplied representing the document to be signed is not valid."); 93 | } 94 | 95 | return $doc; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/xml/Incl.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | */ 23 | 24 | /** 25 | * Include is part of GenericTimeStampType 26 | * The classname 'Incl' is used because 'Include' is a keyword so cannot be used. 27 | * However, the Xml tag used will still be 'Include' 28 | */ 29 | class Incl extends XmlCore 30 | { 31 | /** 32 | * Represents @ReferenceData 33 | * @var bool 34 | */ 35 | public $referenceData; 36 | 37 | /** 38 | * The Uri defining the reference to include 39 | * @var string 40 | */ 41 | public $uri = null; 42 | 43 | /** 44 | * Create an <Include> instance 45 | * @param boolean $referenceData 46 | * @param string $uri 47 | */ 48 | public function __construct( $uri = null, $referenceData = true ) 49 | { 50 | $this->referenceData = $referenceData; 51 | $this->uri = $uri; 52 | } 53 | 54 | /** 55 | * Returns the instance local name 56 | * @return string 57 | */ 58 | public function getLocalName() 59 | { 60 | return ElementNames::Include; 61 | } 62 | 63 | /** 64 | * Read the Xml node and create appropriate classes 65 | * By the time this function has been called, the class has been 66 | * instantiated so the work to do is to read the contents and create 67 | * other classes (if appropriate) 68 | * @param \DOMElement $node 69 | * @return Include 70 | */ 71 | public function loadInnerXml( $node ) 72 | { 73 | parent::loadInnerXml( $node ); 74 | 75 | $attr = $node->getAttributeNode( AttributeNames::URI ); 76 | if ( $attr ) 77 | { 78 | $this->uri = $attr->value; 79 | } 80 | 81 | $attr = $node->getAttributeNode( AttributeNames::ReferencedData ); 82 | if ( $attr ) 83 | { 84 | $this->referenceData = $attr->value; 85 | } 86 | 87 | return $this; 88 | } 89 | 90 | /** 91 | * Generates Xml nodes for the instance. 92 | * 93 | * @param \DOMElement $parentNode 94 | * @param string[] $attributes 95 | * @param \DOMElement $insertAfter 96 | * @return \DOMElement 97 | */ 98 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 99 | { 100 | $newElement = parent::generateXml( $parentNode, array( AttributeNames::URI => $this->uri, AttributeNames::ReferencedData => $this->referenceData ? 'true' : 'false' ), $insertAfter ); 101 | } 102 | 103 | /** 104 | * Validate @Uri 105 | * @throws \Exception 106 | */ 107 | public function validateElement() 108 | { 109 | if ( ! $this->uri ) 110 | throw new \Exception("A Uri MUST be provided"); 111 | } 112 | } -------------------------------------------------------------------------------- /src/xml/UnsignedSignatureProperties.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | * 34 | * 35 | * 36 | * 37 | */ 38 | 39 | /** 40 | * Creates a node for <UnsignedSignatureProperties> which is a container for a collection of elements 41 | */ 42 | class UnsignedSignatureProperties extends PropertiesCollection 43 | { 44 | /** 45 | * Allow a user to pass in the objects for which elements are to be created 46 | * @param XmlCore|XmlCore[] $unsignedSignatureProperties 47 | * @param string $id 48 | */ 49 | public function __construct( 50 | $unsignedSignatureProperties = null, 51 | $id = null 52 | ) 53 | { 54 | parent::__construct( $unsignedSignatureProperties ); 55 | 56 | // Check any instances are valid 57 | $this->checkProperties(); 58 | 59 | $this->id = $id; 60 | } 61 | 62 | /** 63 | * Returns the instance local name 64 | * @return string 65 | */ 66 | public function getLocalName() 67 | { 68 | return ElementNames::UnsignedSignatureProperties; 69 | } 70 | 71 | /** 72 | * Check all properties are valid property types 73 | * @return bool 74 | * @throws \Exception 75 | */ 76 | private function checkProperties() 77 | { 78 | if ( ! $this->properties ) return false; 79 | 80 | foreach( $this->properties as $unsignedSignatureProperty ) 81 | { 82 | if ( $unsignedSignatureProperty instanceof UnsignedSignatureProperty ) continue; 83 | 84 | $basename = get_class( $unsignedSignatureProperty ); 85 | throw new \Exception("All unsigned signature properties must be valid types. Found <$basename>"); 86 | } 87 | 88 | return true; 89 | } 90 | 91 | /** 92 | * Allow the properties to validate themselves 93 | * @return void 94 | * @throws \Exception 95 | */ 96 | public function validateElement() 97 | { 98 | parent::validateElement(); 99 | 100 | if ( ! $this->checkProperties() ) return; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Utils/XPath.php: -------------------------------------------------------------------------------- 1 | "XML_ELEMENT_NODE", 52 | XML_ATTRIBUTE_NODE => "XML_ATTRIBUTE_NODE", 53 | XML_TEXT_NODE => "XML_TEXT_NODE", 54 | XML_CDATA_SECTION_NODE => "XML_CDATA_SECTION_NODE", 55 | XML_ENTITY_REF_NODE => "XML_ENTITY_REF_NODE", 56 | XML_ENTITY_NODE => "XML_ENTITY_NODE", 57 | XML_PI_NODE => "XML_PI_NODE", 58 | XML_COMMENT_NODE => "XML_COMMENT_NODE", 59 | XML_DOCUMENT_NODE => "XML_DOCUMENT_NODE", 60 | XML_DOCUMENT_TYPE_NODE => "XML_DOCUMENT_TYPE_NODE", 61 | XML_DOCUMENT_FRAG_NODE => "XML_DOCUMENT_FRAG_NODE", 62 | XML_NOTATION_NODE => "XML_NOTATION_NODE", 63 | XML_HTML_DOCUMENT_NODE => "XML_HTML_DOCUMENT_NODE", 64 | XML_DTD_NODE => "XML_DTD_NODE", 65 | XML_ELEMENT_DECL_NODE => "XML_ELEMENT_DECL_NODE", 66 | XML_ATTRIBUTE_DECL_NODE => "XML_ATTRIBUTE_DECL_NODE", 67 | XML_ENTITY_DECL_NODE => "XML_ENTITY_DECL_NODE", 68 | XML_NAMESPACE_DECL_NODE => "XML_NAMESPACE_DECL_NODE", 69 | XML_ATTRIBUTE_CDATA => "XML_ATTRIBUTE_CDATA", 70 | XML_ATTRIBUTE_ID => "XML_ATTRIBUTE_ID", 71 | XML_ATTRIBUTE_IDREF => "XML_ATTRIBUTE_IDREF", 72 | XML_ATTRIBUTE_IDREFS => "XML_ATTRIBUTE_IDREFS", 73 | XML_ATTRIBUTE_ENTITY => "XML_ATTRIBUTE_ENTITY", 74 | XML_ATTRIBUTE_NMTOKEN => "XML_ATTRIBUTE_NMTOKEN", 75 | XML_ATTRIBUTE_NMTOKENS => "XML_ATTRIBUTE_NMTOKENS", 76 | XML_ATTRIBUTE_ENUMERATION => "XML_ATTRIBUTE_ENUMERATION", 77 | XML_ATTRIBUTE_NOTATION => "XML_ATTRIBUTE_NOTATION" 78 | ); 79 | 80 | $nodesOutput = ""; 81 | foreach( $nodelist as $node ) 82 | { 83 | $nodesOutput .= $elementTypes[ $node->nodeType ] . "\t\t"; 84 | $nodesOutput .= $node->nodeName . "\t\t"; 85 | $nodesOutput .= $node->parentNode ? $node->parentNode->getNodePath() : "root"; 86 | $nodesOutput .= "\n"; 87 | } 88 | file_put_contents( __DIR__ . "/../../../nodesOutput.txt", $nodesOutput ); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/xml/XPathFilter2.php: -------------------------------------------------------------------------------- 1 | 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | * 34 | * 35 | */ 36 | 37 | /** 38 | * Creates a node for <Transform> 39 | */ 40 | class XPathFilter2 extends XPathFilter 41 | { 42 | /** 43 | * The filter to use with the xpath query. Can be one of the constants defined in the Filter class. 44 | * @var string 45 | */ 46 | public $filter = XPathFilterName::union; 47 | 48 | /** 49 | * Assign one of more <XPath> to this instance 50 | * @param string $query 51 | * @param string $filter 52 | * @param string[] $namespaces A set of namespaces used in the XPath query indexed by prefix 53 | */ 54 | public function __construct( $query = null, $filter = null, $namespaces = array() ) 55 | { 56 | $this->filter = $filter; 57 | parent::__construct( $query, $namespaces ); 58 | $this->defaultNamespace = XMLSecurityDSig::XPATH_FILTER2; 59 | } 60 | 61 | /** 62 | * Create an <XPath> with @Filter 63 | * 64 | * @param \DOMElement $parentNode 65 | * @param string[] $attributes 66 | * @param \DOMElement $insertAfter 67 | * @return \DOMElement 68 | */ 69 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 70 | { 71 | $newElement = parent::generateXml( $parentNode, array( AttributeNames::Filter => $this->filter ), $insertAfter ); 72 | 73 | $filter = $newElement->ownerDocument->createAttribute( AttributeNames::Filter ); 74 | $filter->value = $this->filter; 75 | $newElement->appendChild( $filter ); 76 | return $newElement; 77 | } 78 | 79 | /** 80 | * Read the filter attribute 81 | * @param \DOMElement $node 82 | * @return void 83 | */ 84 | public function loadInnerXml($node) 85 | { 86 | parent::loadInnerXml( $node ); 87 | 88 | $attr = $node->getAttributeNode( AttributeNames::Filter ); 89 | if ( ! $attr ) 90 | throw new \Exception("The XPath filter 2 @Filter cannot be found. This is a required attribute."); 91 | 92 | $this->filter = $attr->value; 93 | } 94 | 95 | /** 96 | * Validate the filter: that it exists and has one of the three valid value 97 | * @return void 98 | */ 99 | public function validateElement() 100 | { 101 | parent::validateElement(); 102 | 103 | $reflection = new \ReflectionClass( XPathFilterName::class ); 104 | $filter = $reflection->getConstant( $this->filter ); 105 | if ( $filter ) return; 106 | throw new \Exception("The XPath filter 2 @Filter does not have a valid value: {$this->filter}"); 107 | } 108 | } 109 | 110 | /** 111 | * Defines the three filters 112 | */ 113 | class XPathFilterName 114 | { 115 | const intersect = "intersect"; 116 | const subtract = "subtract"; 117 | const union = "union"; 118 | } -------------------------------------------------------------------------------- /src/xml/CompleteCertificateRefs.php: -------------------------------------------------------------------------------- 1 | 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | */ 26 | 27 | /** 28 | * Creates a node for <CompleteCertificateRefs> 29 | */ 30 | class CompleteCertificateRefs extends XmlCore implements UnsignedSignatureProperty 31 | { 32 | /** 33 | * A <CertRefs> 34 | * @var CertRefs 35 | */ 36 | public $certRefs = null; 37 | 38 | /** 39 | * Create an instance of <CompleteCertificateRefs> and pass in an instance of <CertRefs> 40 | * @param CertRefs $certRefs 41 | * @param string $id 42 | */ 43 | public function __construct( $certRefs = null, $id = null ) 44 | { 45 | $this->certRefs = $certRefs; 46 | $this->id = $id; 47 | } 48 | 49 | /** 50 | * Returns the instance local name 51 | * @return string 52 | */ 53 | public function getLocalName() 54 | { 55 | return ElementNames::CompleteCertificateRefs; 56 | } 57 | 58 | /** 59 | * Create <CompleteCertificateRefs> and any descendent elements 60 | * @param \DOMElement $parentNode 61 | * @param string[] $attributes 62 | * @param \DOMElement $insertAfter 63 | * @return \DOMElement 64 | */ 65 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 66 | { 67 | // Create a node for this element 68 | $newElement = parent::generateXml( $parentNode, $attributes, $insertAfter ); 69 | 70 | if ( $this->certRefs ) 71 | $this->certRefs->generateXml( $newElement ); 72 | } 73 | 74 | /** 75 | * Load the child elements of <CompleteCertificateRefs> 76 | * 77 | * @param \DOMElement $node 78 | * @return CompleteCertificateRefs 79 | */ 80 | public function loadInnerXml( $node ) 81 | { 82 | parent::loadInnerXml( $node ); 83 | 84 | foreach ( $node->childNodes as $childNode ) 85 | { 86 | /** @var \DOMElement $childNode */ 87 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 88 | 89 | switch( $childNode->localName ) 90 | { 91 | case ElementNames::CertRefs: 92 | $this->certRefs = new CertRefs(); 93 | $this->certRefs->loadInnerXml( $childNode ); 94 | break; 95 | } 96 | } 97 | } 98 | 99 | /** 100 | * Vaildate <CompleteCertificateRefs> and any descendent elements 101 | * @return void 102 | */ 103 | public function validateElement() 104 | { 105 | // Create a node for this element 106 | parent::validateElement(); 107 | 108 | if ( $this->certRefs ) 109 | $this->certRefs->validateElement(); 110 | } 111 | 112 | /** 113 | * Calls the closure in $callback and does the same on any descendents 114 | * @param Closure $callback 115 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 116 | * @return XmlCore 117 | */ 118 | public function traverse( $callback, $depthFirst = false ) 119 | { 120 | if ( $callback instanceof \Closure ) 121 | { 122 | if ( ! $depthFirst ) 123 | parent::traverse( $callback, $depthFirst ); 124 | 125 | if ( $this->certDigest ) 126 | $this->certRefs->traverse( $callback, $depthFirst ); 127 | 128 | if ( $depthFirst ) 129 | parent::traverse( $callback, $depthFirst ); 130 | } 131 | return $this; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/xml/ResponderID.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Represents <ResponderID> 28 | */ 29 | class ResponderID extends XmlCore 30 | { 31 | /** 32 | * Represents <ByName> 33 | * @var string (required) 34 | */ 35 | public $name; 36 | 37 | /** 38 | * Represents <ByKey> 39 | * @var string (required) 40 | */ 41 | public $key; 42 | 43 | /** 44 | * Create <ResponderID> by name 45 | * @param string $name 46 | * @return ResponderID 47 | */ 48 | public static function byName( $name ) 49 | { 50 | $id = new ResponderID(); 51 | $id->name = $name; 52 | return $id; 53 | } 54 | 55 | /** 56 | * Create <ResponderID> by key 57 | * @param string $name 58 | * @return ResponderID 59 | */ 60 | public static function byKey( $key ) 61 | { 62 | $id = new ResponderID(); 63 | $id->key = $key; 64 | return $id; 65 | } 66 | 67 | /** 68 | * Create an <ResponderID> instance 69 | */ 70 | public function __construct() {} 71 | 72 | /** 73 | * Returns the instance local name 74 | * @return string 75 | */ 76 | public function getLocalName() 77 | { 78 | return ElementNames::ResponderID; 79 | } 80 | 81 | /** 82 | * Read the Xml node and create appropriate classes 83 | * By the time this function has been called, the class has been 84 | * instantiated so the work to do is to read the contents and create 85 | * other classes (if appropriate) 86 | * @param \DOMElement $node 87 | * @return ResponderID 88 | */ 89 | public function loadInnerXml( $node ) 90 | { 91 | parent::loadInnerXml( $node ); 92 | 93 | foreach ( $node->childNodes as $childNode ) 94 | { 95 | /** @var \DOMElement $childNode */ 96 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 97 | 98 | switch( $childNode->localName ) 99 | { 100 | case ElementNames::ByName: 101 | $this->name = $childNode->nodeValue; 102 | break; 103 | 104 | case ElementNames::ByKey: 105 | $this->key = $childNode->nodeValue; 106 | break; 107 | } 108 | } 109 | 110 | return $this; 111 | } 112 | 113 | /** 114 | * Generates Xml nodes for the instance. 115 | * 116 | * @param \DOMElement $parentNode 117 | * @param string[] $attributes 118 | * @param \DOMElement $insertAfter 119 | * @return \DOMElement 120 | */ 121 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 122 | { 123 | $newElement = parent::generateXml( $parentNode, array( AttributeNames::URI => $this->uri ), $insertAfter ); 124 | 125 | if ( $this->name ) 126 | { 127 | $name = $parentNode->ownerDocument->createElement( ElementNames::ByName, $this->name ); 128 | $newElement->appendChild( $name ); 129 | } 130 | 131 | if ( $this->key ) 132 | { 133 | $key = $parentNode->ownerDocument->createElement( ElementNames::ByKey, $this->key ); 134 | $newElement->appendChild( $key ); 135 | } 136 | } 137 | 138 | /** 139 | * Validate @Uri 140 | * @throws \Exception 141 | */ 142 | public function validateElement() 143 | { 144 | parent::validateElement(); 145 | 146 | if ( $this->name && $this->key ) 147 | throw new \Exception("Only OR should be provided"); 148 | 149 | if ( $this->key ) 150 | Base64String::validateBase64String( $this->key ); 151 | } 152 | } -------------------------------------------------------------------------------- /src/xml/SigPolicyHash.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <SigPolicyHash> 28 | */ 29 | class SigPolicyHash extends XmlCore 30 | { 31 | /** 32 | * A <DigestMethod> 33 | * @var DigestMethod 34 | */ 35 | public $digestMethod = null; 36 | 37 | /** 38 | * A <DigestValue> 39 | * @var DigestValue 40 | */ 41 | public $digestValue = null; 42 | 43 | /** 44 | * Create an instance of <SigPolicyHash> and pass in an instance of <DigestMethod> and <DigestValue> 45 | * @param DigestMethod $digestMethod 46 | * @param DigestValue $digestValue 47 | */ 48 | public function __construct( $digestMethod = null, $digestValue = null ) 49 | { 50 | $this->digestMethod = self::createConstructor( $digestMethod, DigestMethod::class ); 51 | $this->digestValue = self::createConstructor( $digestValue, DigestValue::class ); 52 | } 53 | 54 | /** 55 | * Returns the instance local name 56 | * @return string 57 | */ 58 | public function getLocalName() 59 | { 60 | return ElementNames::SigPolicyHash; 61 | } 62 | 63 | /** 64 | * Load the child elements of <SigPolicyHash> 65 | * @param \DOMElement $node 66 | * @return SigPolicyHash 67 | */ 68 | public function loadInnerXml( $node ) 69 | { 70 | parent::loadInnerXml( $node ); 71 | 72 | foreach ( $node->childNodes as $childNode ) 73 | { 74 | /** @var \DOMElement $childNode */ 75 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 76 | 77 | switch( $childNode->localName ) 78 | { 79 | case ElementNames::DigestMethod: 80 | $this->digestMethod = new DigestMethod(); 81 | $this->digestMethod->loadInnerXml( $childNode ); 82 | break; 83 | 84 | case ElementNames::DigestValue: 85 | $this->digestValue = new DigestValue(); 86 | $this->digestValue->loadInnerXml( $childNode ); 87 | break; 88 | } 89 | } 90 | } 91 | 92 | /** 93 | * Create <SigPolicyHash> and any descendent elements 94 | * 95 | * @param \DOMElement $parentNode 96 | * @param string[] $attributes 97 | * @param \DOMElement $insertAfter 98 | * @return \DOMElement 99 | */ 100 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 101 | { 102 | // Create a node for this element 103 | $newElement = parent::generateXml( $parentNode, $attributes, $insertAfter ); 104 | 105 | if ( $this->digestMethod ) 106 | $this->digestMethod->generateXml( $newElement ); 107 | 108 | if ( $this->digestValue ) 109 | $this->digestValue->generateXml( $newElement ); 110 | } 111 | 112 | /** 113 | * Calls the closure in $callback and does the same on any descendents 114 | * @param Closure $callback 115 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 116 | * @return XmlCore 117 | */ 118 | public function traverse( $callback, $depthFirst = false ) 119 | { 120 | if ( $callback instanceof \Closure ) 121 | { 122 | if ( ! $depthFirst ) 123 | parent::traverse( $callback, $depthFirst ); 124 | 125 | if ( $this->digestMethod ) 126 | $this->digestMethod->traverse( $callback, $depthFirst ); 127 | 128 | if ( $this->digestValue ) 129 | $this->digestValue->traverse( $callback, $depthFirst ); 130 | 131 | if ( $depthFirst ) 132 | parent::traverse( $callback, $depthFirst ); 133 | } 134 | return $this; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/xml/CompleteCertificateRefsV2.php: -------------------------------------------------------------------------------- 1 | 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | */ 28 | 29 | /** 30 | * Creates a node for <CompleteCertificateRefsV2> 31 | */ 32 | class CompleteCertificateRefsV2 extends XmlCore 33 | { 34 | /** 35 | * A <CertRefs> 36 | * @var CertRefsV2 37 | */ 38 | public $certRefs = null; 39 | 40 | /** 41 | * Create an instance of <CompleteCertificateRefs> and pass in an instance of <CertRefs> 42 | * @param CertRefsV2 $certRefs 43 | * @param string $id 44 | */ 45 | public function __construct( $certRefs = null, $id = null ) 46 | { 47 | $this->certRefs = $certRefs; 48 | $this->id = $id; 49 | } 50 | 51 | /** 52 | * Returns the instance local name 53 | * @return string 54 | */ 55 | public function getLocalName() 56 | { 57 | return ElementNames::CompleteCertificateRefsV2; 58 | } 59 | 60 | /** 61 | * Create <CompleteCertificateRefsV2> and any descendent elements 62 | * @param \DOMElement $parentNode 63 | * @param string[] $attributes 64 | * @param \DOMElement $insertAfter 65 | * @return \DOMElement 66 | */ 67 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 68 | { 69 | // Create a node for this element 70 | $newElement = parent::generateXml( $parentNode, $attributes, $insertAfter ); 71 | 72 | if ( $this->certRefs ) 73 | $this->certRefs->generateXml( $newElement ); 74 | } 75 | 76 | /** 77 | * Load the child elements of <CompleteCertificateRefsV2> 78 | * 79 | * @param \DOMElement $node 80 | * @return CompleteCertificateRefsV2 81 | */ 82 | public function loadInnerXml( $node ) 83 | { 84 | parent::loadInnerXml( $node ); 85 | 86 | foreach ( $node->childNodes as $childNode ) 87 | { 88 | /** @var \DOMElement $childNode */ 89 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 90 | 91 | switch( $childNode->localName ) 92 | { 93 | case ElementNames::CertRefs: 94 | $this->certRefs = new CertRefsV2(); 95 | $this->certRefs->loadInnerXml( $childNode ); 96 | break; 97 | } 98 | } 99 | } 100 | 101 | /** 102 | * Vaildate <CompleteCertificateRefsV2> and any descendent elements 103 | * @return void 104 | */ 105 | public function validateElement() 106 | { 107 | // Create a node for this element 108 | parent::validateElement(); 109 | 110 | if ( $this->certRefs ) 111 | $this->certRefs->validateElement(); 112 | } 113 | 114 | /** 115 | * Calls the closure in $callback and does the same on any descendents 116 | * @param Closure $callback 117 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 118 | * @return XmlCore 119 | */ 120 | public function traverse( $callback, $depthFirst = false ) 121 | { 122 | if ( $callback instanceof \Closure ) 123 | { 124 | if ( ! $depthFirst ) 125 | parent::traverse( $callback, $depthFirst ); 126 | 127 | if ( $this->certRefs ) 128 | $this->certRefs->traverse( $callback, $depthFirst ); 129 | 130 | if ( $depthFirst ) 131 | parent::traverse( $callback, $depthFirst ); 132 | } 133 | return $this; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/InputResourceInfo.php: -------------------------------------------------------------------------------- 1 | . 4 | * All rights reserved. 5 | * 6 | * GPL 3.0 7 | */ 8 | 9 | namespace lyquidity\xmldsig; 10 | 11 | use lyquidity\xmldsig\xml\Transform; 12 | use lyquidity\xmldsig\xml\Transforms; 13 | 14 | /** 15 | * Records information about to data to be signed. 16 | */ 17 | class InputResourceInfo extends BaseInputResourceInfo 18 | { 19 | /** 20 | * Flag defining whether the signature should be detached or added to the source document 21 | * @var boolean (default: true) 22 | */ 23 | public $detached = true; 24 | 25 | /** 26 | * An optional Transforms instance allows a caller to define how the referenced 27 | * content should be transformed before the digest is computed. For example, it 28 | * might be necessary to make sure only certain types of content are in the XML 29 | * to be signed. An example is removing aany existing signature. Another is to 30 | * specify a particular type of canonicalization. 31 | * 32 | * @var Transforms 33 | */ 34 | public $transforms = null; 35 | 36 | /** 37 | * This will be used to set @Id when the static sign function is used 38 | * 39 | * @var string 40 | */ 41 | public $signatureId = null; 42 | 43 | /** 44 | * The value of an id to select when signing 45 | * 46 | * @var string 47 | */ 48 | public $uri = null; 49 | 50 | /** 51 | * Returns true if the transforms contains one that is enveloped 52 | * 53 | * @var boolean 54 | */ 55 | public function hasEnveloped() 56 | { 57 | return $this->transforms 58 | ? $this->transforms->hasEnveloped() 59 | : false; 60 | } 61 | 62 | /** 63 | * Create signature resource descriptor 64 | * @param string $resource 65 | * @param int $type (optional: default = file) An or'd value of ResourceInfo::file ResourceInfo::binary ResourceInfo::des with ResourceInfo::base64 66 | * @param string $saveLocation (optional: default = file location) 67 | * @param string $saveFilename (optional: default = file name) 68 | * @param Transforms $transforms (optional) 69 | * @param bool $detached (optional: default = true) 70 | * @param string $signatureId (optional) 71 | * @param bool $hugeFile (optional) For use where there is a huge text node (> 10MB) 72 | */ 73 | public function __construct( $resource, $type = self::file, $saveLocation = null, $saveFilename = null, $transforms = null, $detached = true, $signatureId = null, $hugeFile = false ) 74 | { 75 | parent::__construct( $resource, $type, $saveLocation, $saveFilename ); 76 | $this->transforms = $transforms; 77 | $this->detached = $detached; 78 | $this->signatureId = $signatureId; 79 | $this->hugeFile = $hugeFile; 80 | 81 | if ( ! $this->isFile() ) return; 82 | 83 | if ( ! $this->saveLocation ) $this->saveLocation = dirname( $this->resource ); 84 | if ( ! $this->saveFilename ) $this->saveFilename = basename( $this->resource ); 85 | } 86 | 87 | /** 88 | * Converts a typed Transforms instance into the type of array used by XMLSecurityDSig 89 | * @param bool $removeSignatures 90 | * @return string[] 91 | */ 92 | public function convertTransforms( $removeSignatures ) 93 | { 94 | $result = array(); 95 | 96 | if ( $removeSignatures && ( ! $this->transforms || ! $this->transforms instanceof Transforms ) && ! $this->hasEnveloped() ) 97 | { 98 | // Whe working with an attached signature, there will be a signature 99 | // in the input document so add a transform to remove it/them 100 | $envelopedTransform = new Transform( XMLSecurityDSig::ENV_SIG ); 101 | $result[] = $envelopedTransform->toSimpleRepresentation(); 102 | unset( $envelopedTransform ); 103 | } 104 | else if( ! $removeSignatures && ! $this->transforms ) 105 | { 106 | // Otherwise, if there are no transforms, create one that canonicalizes 107 | $canonicalizedTransform = new Transform( XMLSecurityDSig::C14N ); 108 | $result[] = $canonicalizedTransform->toSimpleRepresentation(); 109 | unset( $canonicalizedTransform ); 110 | } 111 | 112 | if ( $this->transforms && $this->transforms instanceof Transforms ) 113 | foreach( $this->transforms->transforms as $transform ) 114 | { 115 | $result[] = $transform->toSimpleRepresentation(); 116 | } 117 | 118 | return $result; 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/xml/DigestAlgAndValue.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <DigestAlgAndValue> 28 | */ 29 | class DigestAlgAndValue extends XmlCore 30 | { 31 | /** 32 | * A <DigestMethod> 33 | * @var DigestMethod 34 | */ 35 | public $digestMethod = null; 36 | 37 | /** 38 | * A <DigestValue> 39 | * @var DigestValue 40 | */ 41 | public $digestValue = null; 42 | 43 | /** 44 | * Creage an instance of and pass in an instance of 45 | * @param DigestMethod $digestMethod 46 | * @param DigestValue $digestValue 47 | */ 48 | public function __construct( $digestMethod = null, $digestValue = null ) 49 | { 50 | $this->digestMethod = $digestMethod; 51 | $this->digestValue = $digestValue; 52 | } 53 | 54 | /** 55 | * Returns the instance local name 56 | * @return string 57 | */ 58 | public function getLocalName() 59 | { 60 | return ElementNames::DigestAlgAndValue; 61 | } 62 | 63 | /** 64 | * Create <DigestAlgAndValue> and any descendent elements 65 | * @param \DOMElement $parentNode 66 | * @param string[] $attributes 67 | * @param \DOMElement $insertAfter 68 | * @return \DOMElement 69 | */ 70 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 71 | { 72 | // Create a node for this element 73 | $newElement = parent::generateXml( $parentNode, $attributes, $insertAfter ); 74 | 75 | $this->digestMethod->generateXml( $newElement ); 76 | $this->digestValue->generateXml( $newElement ); 77 | } 78 | 79 | /** 80 | * Read the Xml node and create appropriate classes 81 | * By the time this function has been called, the class has been 82 | * instantiated so the work to do is to read the contents and create 83 | * other classes (if appropriate) 84 | * @param \DOMElement $node 85 | * @return DigestAlgAndValue 86 | */ 87 | public function loadInnerXml($node) 88 | { 89 | parent::loadInnerXml( $node ); 90 | // No attributes for this element 91 | 92 | // Look for elements with the tag <X509AttributeCertificate> or <OtherAttributeCertificate> 93 | foreach( $node->childNodes as $childNode ) 94 | { 95 | /** @var \DOMElement $node */ 96 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 97 | 98 | switch( $childNode->localName ) 99 | { 100 | case ElementNames::DigestMethod: 101 | $this->digestMethod = new DigestMethod(); 102 | $this->digestMethod->loadInnerXml( $childNode ); 103 | break; 104 | 105 | case ElementNames::DigestValue: 106 | $this->digestValue = new DigestValue(); 107 | $this->digestValue->loadInnerXml( $childNode ); 108 | break; 109 | } 110 | } 111 | 112 | return $this; 113 | } 114 | 115 | /** 116 | * Validate <DigestMethod> and <DigestValue>. 117 | * @throws \Exception 118 | */ 119 | public function validateElement() 120 | { 121 | parent::validateElement(); 122 | 123 | $this->digestMethod->validateElement(); 124 | $this->digestValue->validateElement(); 125 | } 126 | 127 | /** 128 | * Calls the closure in $callback and does the same on any descendents 129 | * @param Closure $callback 130 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 131 | * @return XmlCore 132 | */ 133 | public function traverse( $callback, $depthFirst = false ) 134 | { 135 | if ( $callback instanceof \Closure ) 136 | { 137 | if ( ! $depthFirst ) 138 | parent::traverse( $callback, $depthFirst ); 139 | 140 | if ( $this->digestMethod ) 141 | $this->digestMethod->traverse( $callback, $depthFirst ); 142 | 143 | if ( $this->digestValue ) 144 | $this->digestValue->traverse( $callback, $depthFirst ); 145 | 146 | if ( $depthFirst ) 147 | parent::traverse( $callback, $depthFirst ); 148 | } 149 | return $this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/xml/Cert.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <Cert> 28 | */ 29 | class Cert extends XmlCore 30 | { 31 | /** 32 | * A <CertDigest> 33 | * @var CertDigest 34 | */ 35 | public $certDigest = null; 36 | 37 | /** 38 | * A <IssuerSerial> 39 | * @var IssuerSerial 40 | */ 41 | public $issuerSerial = null; 42 | 43 | /** 44 | * Create an instance of <Cert> and pass in an instance of <CertDigest> and <IssuerSerial> 45 | * @param CertDigest $certDigest 46 | * @param IssuerSerial $issuerSerial 47 | */ 48 | public function __construct( $certDigest = null, $issuerSerial = null ) 49 | { 50 | $this->certDigest = $certDigest; 51 | $this->issuerSerial = $issuerSerial; 52 | } 53 | 54 | /** 55 | * Returns the instance local name 56 | * @return string 57 | */ 58 | public function getLocalName() 59 | { 60 | return ElementNames::Cert; 61 | } 62 | 63 | /** 64 | * Create <Cert> and any descendent elements 65 | * @param \DOMElement $parentNode 66 | * @param string[] $attributes 67 | * @param \DOMElement $insertAfter 68 | * @return \DOMElement 69 | */ 70 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 71 | { 72 | // Create a node for this element 73 | $newElement = parent::generateXml( $parentNode, $attributes, $insertAfter ); 74 | 75 | $this->certDigest->generateXml( $newElement ); 76 | $this->issuerSerial->generateXml( $newElement ); 77 | } 78 | 79 | /** 80 | * Read the Xml node and create appropriate classes 81 | * By the time this function has been called, the class has been 82 | * instantiated so the work to do is to read the contents and create 83 | * other classes (if appropriate) 84 | * @param \DOMElement $node 85 | * @return Cert 86 | */ 87 | public function loadInnerXml($node) 88 | { 89 | parent::loadInnerXml( $node ); 90 | // No attributes for this element 91 | 92 | // Look for elements with the tag <X509AttributeCertificate> or <OtherAttributeCertificate> 93 | foreach( $node->childNodes as $childNode ) 94 | { 95 | /** @var \DOMElement $node */ 96 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 97 | 98 | switch( $childNode->localName ) 99 | { 100 | case ElementNames::CertDigest: 101 | $this->certDigest = new CertDigest(); 102 | $this->certDigest->loadInnerXml( $childNode ); 103 | break; 104 | 105 | case ElementNames::IssuerSerial: 106 | $this->issuerSerial = new IssuerSerial(); 107 | $this->issuerSerial->loadInnerXml( $childNode ); 108 | break; 109 | } 110 | } 111 | 112 | return $this; 113 | } 114 | 115 | /** 116 | * Validate <Cert>. 117 | * @throws \Exception 118 | */ 119 | public function validateElement() 120 | { 121 | parent::validateElement(); 122 | 123 | if ( $this->certDigest ) 124 | $this->certDigest->validateElement(); 125 | 126 | if ( $this->issuerSerial ) 127 | $this->issuerSerial->validateElement(); 128 | } 129 | 130 | /** 131 | * Calls the closure in $callback and does the same on any descendents 132 | * @param Closure $callback 133 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 134 | * @return XmlCore 135 | */ 136 | public function traverse( $callback, $depthFirst = false ) 137 | { 138 | if ( $callback instanceof \Closure ) 139 | { 140 | if ( ! $depthFirst ) 141 | parent::traverse( $callback, $depthFirst ); 142 | 143 | if ( $this->certDigest ) 144 | $this->certDigest->traverse( $callback, $depthFirst ); 145 | 146 | if ( $this->issuerSerial ) 147 | $this->issuerSerial->traverse( $callback, $depthFirst ); 148 | 149 | if ( $depthFirst ) 150 | parent::traverse( $callback, $depthFirst ); 151 | } 152 | return $this; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/xml/SPUserNotice.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <SPUserNotice> 28 | */ 29 | class SPUserNotice extends XmlCore 30 | { 31 | /** 32 | * A <NoticeRef> 33 | * @var NoticeRef 34 | */ 35 | public $noticeref = null; 36 | 37 | /** 38 | * A <ExplicitText> 39 | * @var ExplicitText 40 | */ 41 | public $explicitText = null; 42 | 43 | /** 44 | * Create an instance of <SPUserNotice> and pass in an instance of <NoticeRef> and <ExplicitText> 45 | * @param NoticeRef $noticeref 46 | * @param ExplicitText $explicitText 47 | */ 48 | public function __construct( $noticeref = null, $explicitText = null ) 49 | { 50 | $this->noticeref = self::createConstructor( $noticeref, NoticeRef::class ); 51 | $this->explicitText = self::createConstructor( $explicitText, ExplicitText::class ); 52 | } 53 | 54 | /** 55 | * Returns the instance local name 56 | * @return string 57 | */ 58 | public function getLocalName() 59 | { 60 | return ElementNames::SPUserNotice; 61 | } 62 | 63 | /** 64 | * Create <SPUserNotice> and any descendent elements 65 | * 66 | * @param \DOMElement $parentNode 67 | * @param string[] $attributes 68 | * @param \DOMElement $insertAfter 69 | * @return \DOMElement 70 | */ 71 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 72 | { 73 | // Create a node for this element 74 | $newElement = parent::generateXml( $parentNode, $attributes, $insertAfter ); 75 | 76 | if ( $this->noticeref ) 77 | $this->noticeref->generateXml( $newElement ); 78 | 79 | if ( $this->explicitText ) 80 | $this->explicitText->generateXml( $newElement ); 81 | } 82 | 83 | /** 84 | * Load the child elements of <SPUserNotice> 85 | * 86 | * @param \DOMElement $node 87 | * @return SPUserNotice 88 | */ 89 | public function loadInnerXml( $node ) 90 | { 91 | parent::loadInnerXml( $node ); 92 | 93 | foreach ( $node->childNodes as $childNode ) 94 | { 95 | /** @var \DOMElement $childNode */ 96 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 97 | 98 | switch( $childNode->localName ) 99 | { 100 | case ElementNames::NoticeRef: 101 | $this->noticeref = new NoticeRef(); 102 | $this->noticeref->loadInnerXml( $childNode ); 103 | break; 104 | 105 | case ElementNames::ExplicitText: 106 | $this->explicitText = new ExplicitText(); 107 | $this->explicitText->loadInnerXml( $childNode ); 108 | break; 109 | } 110 | } 111 | } 112 | 113 | /** 114 | * Create <SPUserNotice> and any descendent elements 115 | * @param \DOMElement $parentNode 116 | * @param string[] $attributes 117 | * @return void 118 | */ 119 | public function validateElement() 120 | { 121 | // Create a node for this element 122 | parent::validateElement(); 123 | 124 | if ( $this->noticeref ) 125 | $this->noticeref->validateElement(); 126 | 127 | if ( $this->explicitText ) 128 | $this->explicitText->validateElement(); 129 | } 130 | 131 | /** 132 | * Calls the closure in $callback and does the same on any descendents 133 | * @param Closure $callback 134 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 135 | * @return XmlCore 136 | */ 137 | public function traverse( $callback, $depthFirst = false ) 138 | { 139 | if ( $callback instanceof \Closure ) 140 | { 141 | if ( ! $depthFirst ) 142 | parent::traverse( $callback, $depthFirst ); 143 | 144 | if ( $this->noticeref ) 145 | $this->noticeref->traverse( $callback, $depthFirst ); 146 | 147 | if ( $this->explicitText ) 148 | $this->explicitText->traverse( $callback, $depthFirst ); 149 | 150 | if ( $depthFirst ) 151 | parent::traverse( $callback, $depthFirst ); 152 | } 153 | return $this; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/xml/IssuerSerial.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <IssuerSerial> 28 | */ 29 | class IssuerSerial extends XmlCore 30 | { 31 | /** 32 | * A <X509IssuerName> 33 | * @var X509IssuerName 34 | */ 35 | public $x509IssuerName = null; 36 | 37 | /** 38 | * A <X509SerialNumber> 39 | * @var X509SerialNumber 40 | */ 41 | public $x509SerialNumber = null; 42 | 43 | /** 44 | * Create an instance of <IssuerSerial> and pass in instances of <X509IssuerName> and <X509SerialNumber> 45 | * @param X509IssuerName $x509IssuerName 46 | * @param X509SerialNumber $x509SerialNumber 47 | */ 48 | public function __construct( $x509IssuerName = null, $x509SerialNumber = null ) 49 | { 50 | $this->x509IssuerName = $x509IssuerName; 51 | $this->x509SerialNumber = $x509SerialNumber; 52 | } 53 | 54 | /** 55 | * Returns the instance local name 56 | * @return string 57 | */ 58 | public function getLocalName() 59 | { 60 | return ElementNames::IssuerSerial; 61 | } 62 | 63 | /** 64 | * Create <IssuerSerial> and any descendent elements 65 | * 66 | * @param \DOMElement $parentNode 67 | * @param string[] $attributes 68 | * @param \DOMElement $insertAfter 69 | * @return \DOMElement 70 | */ 71 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 72 | { 73 | // Create a node for this element 74 | $newElement = parent::generateXml( $parentNode, $attributes, $insertAfter ); 75 | 76 | $this->x509IssuerName->generateXml( $newElement ); 77 | $this->x509SerialNumber->generateXml( $newElement ); 78 | } 79 | 80 | /** 81 | * Read the Xml node and create appropriate classes 82 | * By the time this function has been called, the class has been 83 | * instantiated so the work to do is to read the contents and create 84 | * other classes (if appropriate) 85 | * @param \DOMElement $node 86 | * @return Cert 87 | */ 88 | public function loadInnerXml($node) 89 | { 90 | parent::loadInnerXml( $node ); 91 | // No attributes for this element 92 | 93 | // Look for elements with the tag <X509AttributeCertificate> or <OtherAttributeCertificate> 94 | foreach( $node->childNodes as $childNode ) 95 | { 96 | /** @var \DOMElement $node */ 97 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 98 | 99 | switch( $childNode->localName ) 100 | { 101 | case ElementNames::X509IssuerName: 102 | $this->x509IssuerName = new X509IssuerName(); 103 | $this->x509IssuerName->loadInnerXml( $childNode ); 104 | break; 105 | 106 | case ElementNames::X509SerialNumber: 107 | $this->x509SerialNumber = new X509SerialNumber(); 108 | $this->x509SerialNumber->loadInnerXml( $childNode ); 109 | break; 110 | } 111 | } 112 | 113 | return $this; 114 | } 115 | 116 | /** 117 | * Validate <IssuerSerial>. 118 | * @throws \Exception 119 | */ 120 | public function validateElement() 121 | { 122 | $this->x509IssuerName->validateElement(); 123 | $this->x509SerialNumber->validateElement(); 124 | } 125 | 126 | /** 127 | * Calls the closure in $callback and does the same on any descendents 128 | * @param Closure $callback 129 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 130 | * @return XmlCore 131 | */ 132 | public function traverse( $callback, $depthFirst = false ) 133 | { 134 | if ( $callback instanceof \Closure ) 135 | { 136 | if ( ! $depthFirst ) 137 | parent::traverse( $callback, $depthFirst ); 138 | 139 | if ( $this->x509IssuerName ) 140 | $this->x509IssuerName->traverse( $callback, $depthFirst ); 141 | 142 | if ( $this->x509SerialNumber ) 143 | $this->x509SerialNumber->traverse( $callback, $depthFirst ); 144 | 145 | if ( $depthFirst ) 146 | parent::traverse( $callback, $depthFirst ); 147 | } 148 | return $this; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/xml/NoticeRef.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Creates a node for <NoticeRef> 28 | */ 29 | class NoticeRef extends XmlCore 30 | { 31 | /** 32 | * A <Organization> 33 | * @var Organization 34 | */ 35 | public $organization = null; 36 | 37 | /** 38 | * A <NoticeNumbers> 39 | * @var NoticeNumbers 40 | */ 41 | public $noticeNumbers = null; 42 | 43 | /** 44 | * Create an instance of <NoticeRef> and pass in an instance of <Organization> and <NoticeNumbers> 45 | * @param Organization $organization 46 | * @param NoticeNumbers $noticeNumbers 47 | */ 48 | public function __construct( $organization = null, $noticeNumbers = null ) 49 | { 50 | $this->organization = self::createConstructor( $organization, Organization::class ); 51 | $this->noticeNumbers = self::createConstructor( $noticeNumbers, NoticeNumbers::class ); 52 | } 53 | 54 | /** 55 | * Returns the instance local name 56 | * @return string 57 | */ 58 | public function getLocalName() 59 | { 60 | return ElementNames::NoticeRef; 61 | } 62 | 63 | /** 64 | * Create <NoticeRef> and any descendent elements 65 | * 66 | * @param \DOMElement $parentNode 67 | * @param string[] $attributes 68 | * @param \DOMElement $insertAfter 69 | * @return \DOMElement 70 | */ 71 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 72 | { 73 | // Create a node for this element 74 | $newElement = parent::generateXml( $parentNode, $attributes, $insertAfter ); 75 | 76 | if ( $this->organization ) 77 | $this->organization->generateXml( $newElement ); 78 | 79 | if ( $this->noticeNumbers ) 80 | $this->noticeNumbers->generateXml( $newElement ); 81 | } 82 | 83 | /** 84 | * Load the child elements of <NoticeRef> 85 | * 86 | * @param \DOMElement $node 87 | * @return NoticeRef 88 | */ 89 | public function loadInnerXml( $node ) 90 | { 91 | parent::loadInnerXml( $node ); 92 | 93 | foreach ( $node->childNodes as $childNode ) 94 | { 95 | /** @var \DOMElement $childNode */ 96 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 97 | 98 | switch( $childNode->localName ) 99 | { 100 | case ElementNames::Organization: 101 | $this->organization = new Organization(); 102 | $this->organization->loadInnerXml( $childNode ); 103 | break; 104 | 105 | case ElementNames::NoticeNumbers: 106 | $this->noticeNumbers = new NoticeNumbers(); 107 | $this->noticeNumbers->loadInnerXml( $childNode ); 108 | break; 109 | } 110 | } 111 | } 112 | 113 | /** 114 | * Create <NoticeRef> and any descendent elements 115 | * @param \DOMElement $parentNode 116 | * @param string[] $attributes 117 | * @return void 118 | */ 119 | public function validateElement() 120 | { 121 | // Create a node for this element 122 | parent::validateElement(); 123 | 124 | if ( $this->organization ) 125 | $this->organization->validateElement(); 126 | 127 | if ( $this->noticeNumbers ) 128 | $this->noticeNumbers->validateElement(); 129 | } 130 | 131 | /** 132 | * Calls the closure in $callback and does the same on any descendents 133 | * @param Closure $callback 134 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 135 | * @return XmlCore 136 | */ 137 | public function traverse( $callback, $depthFirst = false ) 138 | { 139 | if ( $callback instanceof \Closure ) 140 | { 141 | if ( ! $depthFirst ) 142 | parent::traverse( $callback, $depthFirst ); 143 | 144 | if ( $this->organization ) 145 | $this->organization->traverse( $callback, $depthFirst ); 146 | 147 | if ( $this->noticeNumbers ) 148 | $this->noticeNumbers->traverse( $callback, $depthFirst ); 149 | 150 | if ( $depthFirst ) 151 | parent::traverse( $callback, $depthFirst ); 152 | } 153 | return $this; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/xml/CRLRef.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Create <CRLRef> 28 | */ 29 | class CRLRef extends XmlCore 30 | { 31 | /** 32 | * Represents <DigestAlgAndValue> 33 | * @var DigestAlgAndValue (required) 34 | */ 35 | public $digestAlgAndValue; 36 | 37 | /** 38 | * Represents <CRLIdentifier> 39 | * @var CRLIdentifier (required) 40 | */ 41 | public $crlIdentifier; 42 | 43 | /** 44 | * Create an <CRLRef> instance 45 | * @param string $digestAlgAndValue 46 | * @param string $crlIdentifier 47 | */ 48 | public function __construct( $digestAlgAndValue = null, $crlIdentifier = null ) 49 | { 50 | $this->digestAlgAndValue = $digestAlgAndValue; 51 | $this->crlIdentifier = $crlIdentifier; 52 | } 53 | 54 | /** 55 | * Returns the instance local name 56 | * @return string 57 | */ 58 | public function getLocalName() 59 | { 60 | return ElementNames::CRLRef; 61 | } 62 | 63 | /** 64 | * Read the Xml node and create appropriate classes 65 | * By the time this function has been called, the class has been 66 | * instantiated so the work to do is to read the contents and create 67 | * other classes (if appropriate) 68 | * @param \DOMElement $node 69 | * @return CRLRef 70 | */ 71 | public function loadInnerXml( $node ) 72 | { 73 | $newElement = parent::loadInnerXml( $node ); 74 | 75 | foreach ( $node->childNodes as $childNode ) 76 | { 77 | /** @var \DOMElement $childNode */ 78 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 79 | 80 | switch( $childNode->localName ) 81 | { 82 | case ElementNames::DigestAlgAndValue: 83 | $this->digestAlgAndValue = new DigestAlgAndValue(); 84 | $this->digestAlgAndValue->loadInnerXml( $childNode ); 85 | break; 86 | 87 | case ElementNames::CRLIdentifier: 88 | $this->crlIdentifier = new CRLIdentifier(); 89 | $this->crlIdentifier->loadInnerXml( $childNode ); 90 | break; 91 | } 92 | } 93 | 94 | return $this; 95 | } 96 | 97 | /** 98 | * Generates Xml nodes for the instance. 99 | * 100 | * @param \DOMElement $parentNode 101 | * @param string[] $attributes 102 | * @param \DOMElement $insertAfter 103 | * @return \DOMElement 104 | */ 105 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 106 | { 107 | $newElement = parent::generateXml( $parentNode, array( AttributeNames::URI => $this->uri ), $insertAfter ); 108 | 109 | if ( $this->digestAlgAndValue ) 110 | { 111 | $this->digestAlgAndValue->generateXml( $newElement ); 112 | } 113 | 114 | if ( $this->crlIdentifier ) 115 | { 116 | $this->crlIdentifier->generateXml( $newElement ); 117 | } 118 | } 119 | 120 | /** 121 | * Validate CRLRef 122 | * @throws \Exception 123 | */ 124 | public function validateElement() 125 | { 126 | parent::validateElement(); 127 | 128 | if ( $this->digestAlgAndValue ) 129 | { 130 | $this->digestAlgAndValue->validateElement(); 131 | } 132 | 133 | if ( $this->crlIdentifier ) 134 | { 135 | $this->crlIdentifier->validateElement(); 136 | } 137 | } 138 | 139 | /** 140 | * Calls the closure in $callback and does the same on any descendents 141 | * @param Closure $callback 142 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 143 | * @return XmlCore 144 | */ 145 | public function traverse( $callback, $depthFirst = false ) 146 | { 147 | if ( $callback instanceof \Closure ) 148 | { 149 | if ( ! $depthFirst ) 150 | parent::traverse( $callback, $depthFirst ); 151 | 152 | if ( $this->digestAlgAndValue ) 153 | $this->digestAlgAndValue->traverse( $callback, $depthFirst ); 154 | 155 | if ( $this->crlIdentifier ) 156 | $this->crlIdentifier->traverse( $callback, $depthFirst ); 157 | 158 | if ( $depthFirst ) 159 | parent::traverse( $callback, $depthFirst ); 160 | } 161 | return $this; 162 | } 163 | } -------------------------------------------------------------------------------- /src/xml/OCSPRef.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | /** 27 | * Create <OCSPRef> 28 | */ 29 | class OCSPRef extends XmlCore 30 | { 31 | /** 32 | * Represents <DigestAlgAndValue> 33 | * @var DigestAlgAndValue (required) 34 | */ 35 | public $digestAlgAndValue; 36 | 37 | /** 38 | * Represents <OCSPIdentifier> 39 | * @var OCSPIdentifier (required) 40 | */ 41 | public $ocspIdentifier; 42 | 43 | /** 44 | * Create an <OCSPRef> instance 45 | * @param string $digestAlgAndValue 46 | * @param string $ocspIdentifier 47 | */ 48 | public function __construct( $digestAlgAndValue = null, $ocspIdentifier = null ) 49 | { 50 | $this->digestAlgAndValue = $digestAlgAndValue; 51 | $this->ocspIdentifier = $ocspIdentifier; 52 | } 53 | 54 | /** 55 | * Returns the instance local name 56 | * @return string 57 | */ 58 | public function getLocalName() 59 | { 60 | return ElementNames::OCSPRef; 61 | } 62 | 63 | /** 64 | * Read the Xml node and create appropriate classes 65 | * By the time this function has been called, the class has been 66 | * instantiated so the work to do is to read the contents and create 67 | * other classes (if appropriate) 68 | * @param \DOMElement $node 69 | * @return OCSPRef 70 | */ 71 | public function loadInnerXml( $node ) 72 | { 73 | $newElement = parent::loadInnerXml( $node ); 74 | 75 | foreach ( $node->childNodes as $childNode ) 76 | { 77 | /** @var \DOMElement $childNode */ 78 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 79 | 80 | switch( $childNode->localName ) 81 | { 82 | case ElementNames::DigestAlgAndValue: 83 | $this->digestAlgAndValue = new DigestAlgAndValue(); 84 | $this->digestAlgAndValue->loadInnerXml( $childNode ); 85 | break; 86 | 87 | case ElementNames::OCSPIdentifier: 88 | $this->ocspIdentifier = new OCSPIdentifier(); 89 | $this->ocspIdentifier->loadInnerXml( $childNode ); 90 | break; 91 | } 92 | } 93 | 94 | return $this; 95 | } 96 | 97 | /** 98 | * Generates Xml nodes for the instance. 99 | * 100 | * @param \DOMElement $parentNode 101 | * @param string[] $attributes 102 | * @param \DOMElement $insertAfter 103 | * @return \DOMElement 104 | */ 105 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 106 | { 107 | $newElement = parent::generateXml( $parentNode, array( AttributeNames::URI => $this->uri ), $insertAfter ); 108 | 109 | if ( $this->digestAlgAndValue ) 110 | { 111 | $this->digestAlgAndValue->generateXml( $newElement ); 112 | } 113 | 114 | if ( $this->ocspIdentifier ) 115 | { 116 | $this->ocspIdentifier->generateXml( $newElement ); 117 | } 118 | } 119 | 120 | /** 121 | * Validate OCSPRef 122 | * @throws \Exception 123 | */ 124 | public function validateElement() 125 | { 126 | parent::validateElement(); 127 | 128 | if ( $this->digestAlgAndValue ) 129 | { 130 | $this->digestAlgAndValue->validateElement(); 131 | } 132 | 133 | if ( $this->ocspIdentifier ) 134 | { 135 | $this->ocspIdentifier->validateElement(); 136 | } 137 | } 138 | 139 | /** 140 | * Calls the closure in $callback and does the same on any descendents 141 | * @param Closure $callback 142 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 143 | * @return XmlCore 144 | */ 145 | public function traverse( $callback, $depthFirst = false ) 146 | { 147 | if ( $callback instanceof \Closure ) 148 | { 149 | if ( ! $depthFirst ) 150 | parent::traverse( $callback, $depthFirst ); 151 | 152 | if ( $this->digestAlgAndValue ) 153 | $this->digestAlgAndValue->traverse( $callback, $depthFirst ); 154 | 155 | if ( $this->ocspIdentifier ) 156 | $this->ocspIdentifier->traverse( $callback, $depthFirst ); 157 | 158 | if ( $depthFirst ) 159 | parent::traverse( $callback, $depthFirst ); 160 | } 161 | return $this; 162 | } 163 | } -------------------------------------------------------------------------------- /src/xml/Identifier.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | */ 33 | 34 | /** 35 | * Creates a node for <Identifier> 36 | */ 37 | class Identifier extends TextBase 38 | { 39 | /** 40 | * This will become an attrubute @Qualifier with two legal values: 41 | * OIDAsURI or OIDAsURN 42 | * 43 | * @var QualifierValues 44 | */ 45 | public $qualifier = null; 46 | 47 | /** 48 | * Create an <Identifier> instance 49 | * 50 | * @param string $identifier 51 | * @param QualifierValues $qualifier 52 | */ 53 | public function __construct( $identifier = null, $qualifier = null ) 54 | { 55 | // $this->qualifier = QualifierValues::$OIDAsURN; 56 | 57 | parent::__construct( $identifier ); 58 | if ( $qualifier ) 59 | { 60 | $this->validateElement(); 61 | $this->qualifier = $qualifier; 62 | } 63 | } 64 | 65 | /** 66 | * Returns the instance local name 67 | * @return string 68 | */ 69 | public function getLocalName() 70 | { 71 | return ElementNames::Identifier; 72 | } 73 | 74 | /** 75 | * Create <Identifier> and any descendent elements 76 | * 77 | * @param \DOMElement $parentNode 78 | * @param string[] $attributes 79 | * @param \DOMElement $insertAfter 80 | * @return \DOMElement 81 | */ 82 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 83 | { 84 | // Create a node for this element 85 | return parent::generateXml( $parentNode, array( AttributeNames::Qualifier => ( $this->qualifier ? $this->qualifier->getName() : null ) ), $insertAfter ); 86 | } 87 | 88 | /** 89 | * Create objects from an Xml node 90 | * 91 | * @param \DOMElement $node 92 | * @return void 93 | */ 94 | public function loadInnerXml( $node ) 95 | { 96 | $newElement = parent::loadInnerXml( $node ); 97 | 98 | $attr = $node->getAttributeNode( AttributeNames::Qualifier ); 99 | if ( ! $attr ) return; 100 | 101 | $this->qualifier = QualifierValues::fromName( $attr->value ); 102 | } 103 | 104 | /** 105 | * Validate @Qualifier and make sure there is an identifier 106 | * @return void 107 | * @throws \Exception 108 | */ 109 | public function validateElement() 110 | { 111 | parent::validateElement(); 112 | 113 | if ( $this->qualifier ) 114 | if ( $this->qualifier->getName() != QualifierValues::$OIDAsURI->getName() && $this->qualifier->getName() != QualifierValues::$OIDAsURN->getName() ) 115 | throw new \Exception("@Qualifier MUST be 'OIDAsURI' or 'OIDAsURN'"); 116 | } 117 | } 118 | 119 | /** 120 | * Simple class to provide enumerated values for the @Qualifier 121 | */ 122 | abstract class QualifierValues 123 | { 124 | public static $OIDAsURN; 125 | public static $OIDAsURI; 126 | 127 | protected const OIDAsURNName = 'OIDAsURN'; 128 | protected const OIDAsURIName = 'OIDAsURI'; 129 | 130 | public static function fromName( $name ) 131 | { 132 | switch( $name ) 133 | { 134 | case self::OIDAsURIName: 135 | return new QualifierOIDAsURI(); 136 | break; 137 | 138 | case self::OIDAsURNName: 139 | return new QualifierOIDAsURN(); 140 | break; 141 | 142 | default: 143 | error_log("The identifier qualifier found in the Xml is '$name'. Expected 'OIDAsURI' or 'OIDAsURN'."); 144 | return new QualifierOIDAsURN(); 145 | break; 146 | } 147 | } 148 | 149 | public abstract function getName(); 150 | } 151 | 152 | QualifierValues::$OIDAsURI = new QualifierOIDAsURI(); 153 | QualifierValues::$OIDAsURN = new QualifierOIDAsURN(); 154 | 155 | class QualifierOIDAsURN extends QualifierValues 156 | { 157 | public function getName() { return self::OIDAsURNName; } 158 | } 159 | 160 | class QualifierOIDAsURI extends QualifierValues 161 | { 162 | public function getName() { return self::OIDAsURIName; } 163 | } -------------------------------------------------------------------------------- /src/xml/Transform.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * * 26 | */ 27 | 28 | /** 29 | * Creates a node for <Transform> 30 | */ 31 | class Transform extends XmlCore 32 | { 33 | /** 34 | * Maps the algorithm uri to a class 35 | */ 36 | const transformMap= array( 37 | XMLSecurityDSig::C14N => 'Transform', 38 | XMLSecurityDSig::C14N_COMMENTS => 'Transform', 39 | XMLSecurityDSig::EXC_C14N => 'Transform', 40 | XMLSecurityDSig::EXC_C14N_COMMENTS => 'Transform', 41 | XMLSecurityDSig::ENV_SIG => 'Transform', 42 | XMLSecurityDSig::XPATH_FILTER2 => 'TransformXPathFilter2', 43 | XMLSecurityDSig::CXPATH => 'TransformXPath', 44 | XMLSecurityDSig::BASE64 => 'Transform', 45 | XMLSecurityDSig::XSLT => 'Transform' 46 | ); 47 | 48 | /** 49 | * Inclusive canonicalization without comments 50 | */ 51 | const C14N = XMLSecurityDSig::C14N; 52 | /** 53 | * Inclusive canonicalization with comments 54 | */ 55 | const C14N_COMMENTS = XMLSecurityDSig::C14N_COMMENTS; 56 | /** 57 | * Exclusive canonicalization without comments 58 | */ 59 | const EXC_C14N = XMLSecurityDSig::EXC_C14N; 60 | /** 61 | * Exclusive canonicalization with comments 62 | */ 63 | const EXC_C14N_COMMENTS = XMLSecurityDSig::EXC_C14N_COMMENTS; 64 | /** 65 | * Enveloped signatire canonicalization 66 | */ 67 | const ENV_SIG = XMLSecurityDSig::ENV_SIG; 68 | /** 69 | * XPath filter 2.0 70 | */ 71 | const XPATH_FILTER2 = XMLSecurityDSig::XPATH_FILTER2; 72 | /** 73 | * XPath filter 1.0 74 | */ 75 | const CXPATH = XMLSecurityDSig::CXPATH; 76 | /** 77 | * Base64 78 | */ 79 | const BASE64 = XMLSecurityDSig::BASE64; 80 | /** 81 | * An XSLT query to process (not supported) 82 | */ 83 | const XSLT = XMLSecurityDSig::XSLT; 84 | 85 | /** 86 | * This will become an attribute @Algorithm with a restricted list 87 | * of legal values that are listed in the transformMaps property 88 | * 89 | * @var string 90 | */ 91 | public $algorithm = XMLSecurityDSig::C14N; 92 | 93 | /** 94 | * Create a base instance 95 | * @param string $algorithm 96 | */ 97 | public function __construct( $algorithm = null ) 98 | { 99 | $this->defaultNamespace = XMLSecurityDSig::XMLDSIGNS; 100 | if ( $algorithm ) 101 | $this->algorithm = $algorithm; 102 | } 103 | 104 | /** 105 | * Returns the instance local name 106 | * @return string 107 | */ 108 | public function getLocalName() 109 | { 110 | return ElementNames::Transform; 111 | } 112 | 113 | /** 114 | * Create <Transform> and any descendent elements 115 | * 116 | * @param \DOMElement $parentNode 117 | * @param string[] $attributes 118 | * @param \DOMElement $insertAfter 119 | * @return \DOMElement 120 | */ 121 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 122 | { 123 | // Create a node for this element 124 | return parent::generateXml( $parentNode, array( AttributeNames::Algorithm => $this->algorithm ), $insertAfter ); 125 | } 126 | 127 | /** 128 | * Validate the algorithm supplied 129 | * @return void 130 | * @throws \Exception 131 | */ 132 | public function validateElement() 133 | { 134 | // Check the algorithm is valid 135 | if ( isset( self::transformMap[ $this->algorithm ] ) ) return; 136 | 137 | throw new \Exception("The @Algorithm used is not one of the valid Urls: '{$this->algorithm}'"); 138 | } 139 | 140 | /** 141 | * Converts a transform to a simple representation representation for use by XMLSecurityDSig::AddRefInternal() 142 | * @return void 143 | */ 144 | public function toSimpleRepresentation() 145 | { 146 | return $this->algorithm; 147 | } 148 | 149 | /** 150 | * Returns true if the transform algorithm is enveloped 151 | * 152 | * @return boolean 153 | */ 154 | public function isEnveloped() 155 | { 156 | return $this->algorithm == XMLSecurityDSig::ENV_SIG; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/xml/TransformXPath.php: -------------------------------------------------------------------------------- 1 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * * 26 | */ 27 | 28 | /** 29 | * Creates a node for <Transform> 30 | */ 31 | class TransformXPath extends Transform 32 | { 33 | /** 34 | * Represents an optional collection of <Transform> 35 | * @var XPathFilter[] 36 | */ 37 | public $xpaths = array(); 38 | 39 | /** 40 | * Assign one of more to this instance 41 | * @param XPathFilter|XPathFilter[]|string $xpaths 42 | */ 43 | public function __construct( $xpaths = null ) 44 | { 45 | parent::__construct( XMLSecurityDSig::CXPATH ); 46 | 47 | $this->xpaths = self::createConstructorArray( $xpaths, XPathFilter::class ); 48 | } 49 | 50 | /** 51 | * Returns the instance local name 52 | * @return string 53 | */ 54 | public function getLocalName() 55 | { 56 | return ElementNames::Transform; 57 | } 58 | 59 | /** 60 | * Create <TransformXPath> and any descendent elements 61 | * 62 | * @param \DOMElement $parentNode 63 | * @param string[] $attributes 64 | * @param \DOMElement $insertAfter 65 | * @return \DOMElement 66 | */ 67 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 68 | { 69 | // Create a node for this element 70 | $newElement = parent::generateXml( $parentNode, array( AttributeNames::Algorithm => $this->algorithm ), $insertAfter ); 71 | 72 | foreach ( $this->xpaths as $xpath ) 73 | { 74 | $xpath->generateXml( $newElement ); 75 | } 76 | } 77 | 78 | /** 79 | * Generate the correct type of XPath class 80 | * @param string $query (optional) 81 | * @return XPathFilter 82 | */ 83 | protected function createXPathInstance( $query = null ) 84 | { 85 | return new XPathFilter( $query ); 86 | } 87 | 88 | /** 89 | * Load the XPath elements 90 | * 91 | * @param \DOMElement $node 92 | * @return void 93 | */ 94 | public function loadInnerXml($node) 95 | { 96 | parent::loadInnerXml( $node ); 97 | 98 | foreach( $node->childNodes as $subNode ) 99 | { 100 | /** @var \DOMElement $subNode */ 101 | if ( $subNode->nodeType != XML_ELEMENT_NODE ) continue; 102 | if ( $subNode->localName != ElementNames::XPath ) continue; 103 | 104 | // This node is going to be read by XPathFilter 105 | $xpath = $this->createXPathInstance(); 106 | $xpath->loadInnerXml( $subNode ); 107 | $this->xpaths[] = $xpath; 108 | } 109 | } 110 | 111 | /** 112 | * Validate all references are DocumentationReference instances 113 | * @return void 114 | * @throws \Exception 115 | */ 116 | public function validateElement() 117 | { 118 | parent::validateElement(); 119 | 120 | foreach ( $this->xpaths as $xpath ) 121 | { 122 | if ( ! $xpath instanceof XPathFilter ) 123 | throw new \Exception("All children must be of type XPath"); 124 | 125 | $xpath->validateElement(); 126 | } 127 | } 128 | 129 | /** 130 | * Converts a transform to a simple representation representation for use by XMLSecurityDSig::AddRefInternal() 131 | * @return void 132 | */ 133 | public function toSimpleRepresentation() 134 | { 135 | return array( $this->algorithm => array( 136 | array_reduce( $this->xpaths, function( $carry, $xpath ) 137 | { 138 | /** @var XPathFilter $xpath */ 139 | $carry[] = array( 140 | 'query' => $xpath->text, 141 | 'namespaces' => $xpath->namespaces 142 | ); 143 | return $carry; 144 | }, array() ) 145 | ) ); 146 | } 147 | 148 | /** 149 | * Calls the closure in $callback and does the same on any descendents 150 | * @param Closure $callback 151 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 152 | * @return XmlCore 153 | */ 154 | public function traverse( $callback, $depthFirst = false ) 155 | { 156 | if ( $callback instanceof \Closure ) 157 | { 158 | if ( ! $depthFirst ) 159 | parent::traverse( $callback, $depthFirst ); 160 | 161 | foreach( $this->xpaths as $xpath ) 162 | $xpath->traverse( $callback, $depthFirst ); 163 | 164 | if ( $depthFirst ) 165 | parent::traverse( $callback, $depthFirst ); 166 | } 167 | return $this; 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/xml/SignerRole.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | * 34 | * 35 | * 36 | */ 37 | 38 | /** 39 | * Acts as a common base for all text elements like 40 | * Description, Street, City, etc. so they only need 41 | * to specify an element name 42 | */ 43 | class SignerRole extends XmlCore 44 | { 45 | /** 46 | * Implements <ClaimedRoles> 47 | * @var ClaimedRoles 48 | */ 49 | public $claimedRoles = null; 50 | 51 | /** 52 | * Implements <CertifiedRoles> 53 | * @var CertifiedRoles 54 | */ 55 | public $certifiedRoles = null; 56 | 57 | /** 58 | * Create a SignerRole instance 59 | * @param ClaimedRoles|string|string[] $claimedRoles 60 | * @param CertifiedRoles|string|string[] $certifiedRoles 61 | * @return void 62 | */ 63 | public function __construct( $claimedRoles = null, $certifiedRoles = null ) 64 | { 65 | $this->claimedRoles = self::createConstructor( $claimedRoles, ClaimedRoles::class ); 66 | $this->certifiedRoles = self::createConstructor( $certifiedRoles, CertifiedRoles::class ); 67 | } 68 | 69 | /** 70 | * Returns the instance local name 71 | * @return string 72 | */ 73 | public function getLocalName() 74 | { 75 | return ElementNames::SignerRole; 76 | } 77 | 78 | /** 79 | * Create <SignerRole> and any descendent elements 80 | * 81 | * @param \DOMElement $parentNode 82 | * @param string[] $attributes 83 | * @param \DOMElement $insertAfter 84 | * @return \DOMElement 85 | */ 86 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 87 | { 88 | $newElement = parent::generateXml( $parentNode, $attributes, $insertAfter ); 89 | 90 | if ( $this->claimedRoles ) 91 | $this->claimedRoles->generateXml( $newElement ); 92 | 93 | if ( $this->certifiedRoles ) 94 | $this->certifiedRoles->generateXml( $newElement ); 95 | } 96 | 97 | /** 98 | * Create a new Xml representation for $node 99 | * @param \DOMElement $node 100 | */ 101 | public function loadInnerXml($node) 102 | { 103 | parent::loadInnerXml( $node ); 104 | 105 | foreach ( $node->childNodes as $childNode ) 106 | { 107 | /** @var \DOMElement $childNode */ 108 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 109 | 110 | switch ( $childNode->localName ) 111 | { 112 | case ElementNames::ClaimedRoles: 113 | $this->claimedRoles = new ClaimedRoles(); 114 | $this->claimedRoles->loadInnerXml( $childNode ); 115 | break; 116 | 117 | case ElementNames::CertifiedRoles: 118 | $this->certifiedRoles = new CertifiedRoles(); 119 | $this->certifiedRoles->loadInnerXml( $childNode ); 120 | break; 121 | } 122 | } 123 | } 124 | 125 | /** 126 | * Validate this element and all tjhe child elements that are used 127 | * 128 | * @return void 129 | */ 130 | public function validateElement() 131 | { 132 | parent::validateElement(); 133 | 134 | if ( $this->claimedRoles ) 135 | $this->claimedRoles->validateElement( ); 136 | 137 | if ( $this->certifiedRoles ) 138 | $this->certifiedRoles->validateElement(); 139 | } 140 | 141 | /** 142 | * Calls the closure in $callback and does the same on any descendents 143 | * @param Closure $callback 144 | * @param bool $depthFirst (optional: default = false) When true this will call on child nodes first 145 | * @return XmlCore 146 | */ 147 | public function traverse( $callback, $depthFirst = false ) 148 | { 149 | if ( $callback instanceof \Closure ) 150 | { 151 | if ( ! $depthFirst ) 152 | parent::traverse( $callback, $depthFirst ); 153 | 154 | if ( $this->claimedRoles ) 155 | $this->claimedRoles->traverse( $callback, $depthFirst ); 156 | 157 | if ( $this->certifiedRoles ) 158 | $this->certifiedRoles->traverse( $callback, $depthFirst ); 159 | 160 | if ( $depthFirst ) 161 | parent::traverse( $callback, $depthFirst ); 162 | } 163 | return $this; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/xml/CRLIdentifier.php: -------------------------------------------------------------------------------- 1 | 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | * 25 | * 26 | */ 27 | 28 | /** 29 | * Represents <CRLIdentifier> 30 | */ 31 | class CRLIdentifier extends XmlCore 32 | { 33 | /** 34 | * Represents <Issuer> 35 | * @var string (required) 36 | */ 37 | public $issuer; 38 | 39 | /** 40 | * Represents <IssueTime> 41 | * @var string (required) 42 | */ 43 | public $issueTime; 44 | 45 | /** 46 | * Represents <Number> 47 | * @var int 48 | */ 49 | public $number; 50 | 51 | /** 52 | * The Uri defining the reference to include 53 | * @var string 54 | */ 55 | public $uri = null; 56 | 57 | /** 58 | * Create an <CRLIdentifier> instance 59 | * @param string $uri 60 | * @param string $issuer 61 | * @param string $issueTime 62 | * @param int $number 63 | */ 64 | public function __construct( $uri = null, $issuer = null, $issueTime = null, $number = null ) 65 | { 66 | $this->issuer = $issuer; 67 | $this->issueTime = $issueTime; 68 | $this->number = $number; 69 | $this->uri = $uri; 70 | } 71 | 72 | /** 73 | * Returns the instance local name 74 | * @return string 75 | */ 76 | public function getLocalName() 77 | { 78 | return ElementNames::CRLIdentifier; 79 | } 80 | 81 | /** 82 | * Read the Xml node and create appropriate classes 83 | * By the time this function has been called, the class has been 84 | * instantiated so the work to do is to read the contents and create 85 | * other classes (if appropriate) 86 | * @param \DOMElement $node 87 | * @return CRLIdentifier 88 | */ 89 | public function loadInnerXml( $node ) 90 | { 91 | parent::loadInnerXml( $node ); 92 | 93 | $attr = $node->getAttributeNode( AttributeNames::Uri ); 94 | if ( $attr ) 95 | { 96 | $this->uri = $attr->value; 97 | } 98 | 99 | foreach ( $node->childNodes as $childNode ) 100 | { 101 | /** @var \DOMElement $childNode */ 102 | if ( $childNode->nodeType != XML_ELEMENT_NODE ) continue; 103 | 104 | switch( $childNode->localName ) 105 | { 106 | case ElementNames::Issuer: 107 | $this->issuer = $childNode->nodeValue; 108 | break; 109 | 110 | case ElementNames::IssueTime: 111 | $this->issueTime = $childNode->nodeValue; 112 | break; 113 | 114 | case ElementNames::Number: 115 | $this->number = $childNode->nodeValue; 116 | break; 117 | } 118 | } 119 | 120 | return $this; 121 | } 122 | 123 | /** 124 | * Generates Xml nodes for the instance. 125 | * @param \DOMElement $parentNode 126 | * @param string[] $attributes 127 | * @param \DOMElement $insertAfter 128 | * @return \DOMElement 129 | */ 130 | public function generateXml( $parentNode, $attributes = array(), $insertAfter = null ) 131 | { 132 | $newElement = parent::generateXml( $parentNode, array( AttributeNames::URI => $this->uri ), $insertAfter ); 133 | 134 | if ( $this->issuer ) 135 | { 136 | $issuer = $parentNode->ownerDocument->createElement( ElementNames::Issuer, $this->issuer ); 137 | $newElement->appendChild( $issuer ); 138 | } 139 | 140 | if ( $this->issueTime ) 141 | { 142 | $issueTime = $parentNode->ownerDocument->createElement( ElementNames::IssueTime, $this->issueTime ); 143 | $newElement->appendChild( $issueTime ); 144 | } 145 | 146 | if ( $this->number ) 147 | { 148 | $number = $parentNode->ownerDocument->createElement( ElementNames::Number, $this->number ); 149 | $newElement->appendChild( $number ); 150 | } 151 | } 152 | 153 | /** 154 | * Validate @Uri 155 | * @throws \Exception 156 | */ 157 | public function validateElement() 158 | { 159 | parent::validateElement(); 160 | 161 | if ( ! $this->issuer ) 162 | throw new \Exception(" MUST be provided"); 163 | 164 | if ( ! $this->issueTime ) 165 | throw new \Exception(" MUST be provided"); 166 | 167 | if ( preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|(\+|-)\d{2}(:?\d{2})?)$/', $this->issueTime, $parts ) ) 168 | { 169 | // valid string format, can now check parts 170 | $year = $parts[1]; 171 | $month = $parts[2]; 172 | $day = $parts[3]; 173 | 174 | if ( checkdate( $month, $day, $year ) ) 175 | return; 176 | } 177 | 178 | throw new \Exception("The date '{$this->issueTime}' is not valid"); 179 | } 180 | } --------------------------------------------------------------------------------