/** * Create a new \\PKIX\\OCSP\\Request from parameters provided in $params. * The request is minimal but compliant with RFC5019 and can be * used to query an OCSP server. * * @param array $params The array represents the requested * certificate in the from of the CertID. See parseCertID() for * description. */ public function createFromParams(array $params) { /* OCSPRequest ::= SEQUENCE { tbsRequest TBSRequest, optionalSignature [0] EXPLICIT Signature OPTIONAL } TBSRequest ::= SEQUENCE { version [0] EXPLICIT Version DEFAULT v1, requestorName [1] EXPLICIT GeneralName OPTIONAL, requestList SEQUENCE OF Request, requestExtensions [2] EXPLICIT Extensions OPTIONAL } Signature ::= SEQUENCE { signatureAlgorithm AlgorithmIdentifier, signature BIT STRING, certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } Version ::= INTEGER { v1(0) } Request ::= SEQUENCE { reqCert CertID, singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } */ $hashAlg = new \ASN1\TLV((object) array('Class' => TLV_CLASS_UNIVERSAL, 'Type' => TLV_TYPE_CONSTRUCTED, 'Tag' => TLV_TAG_SEQUENCE)); $algorithm = \ASN1\TLV\OID::create(); $algorithm->set($params['hashAlgorithm']); $parameters = \ASN1\TLV\Null::create(); $parameters->set(null); $hashAlg->add($algorithm); $hashAlg->add($parameters); $issuerNameHash = \ASN1\TLV\OctetString::create(); $issuerNameHash->set($params['issuerNameHash']); $issuerKeyHash = \ASN1\TLV\OctetString::create(); $issuerKeyHash->set($params['issuerKeyHash']); $serialNumber = \ASN1\TLV\Integer::create(); $serialNumber->set($params['serialNumber']); $certID = new \ASN1\TLV((object) array('Class' => TLV_CLASS_UNIVERSAL, 'Type' => TLV_TYPE_CONSTRUCTED, 'Tag' => TLV_TAG_SEQUENCE)); $certID->add($hashAlg); $certID->add($issuerNameHash); $certID->add($issuerKeyHash); $certID->add($serialNumber); $request = new \ASN1\TLV((object) array('Class' => TLV_CLASS_UNIVERSAL, 'Type' => TLV_TYPE_CONSTRUCTED, 'Tag' => TLV_TAG_SEQUENCE)); $request->add($certID); $requestList = new \ASN1\TLV((object) array('Class' => TLV_CLASS_UNIVERSAL, 'Type' => TLV_TYPE_CONSTRUCTED, 'Tag' => TLV_TAG_SEQUENCE)); $requestList->add($request); $tbsRequest = new \ASN1\TLV((object) array('Class' => TLV_CLASS_UNIVERSAL, 'Type' => TLV_TYPE_CONSTRUCTED, 'Tag' => TLV_TAG_SEQUENCE)); $tbsRequest->add($requestList); $ocspRequest = new \ASN1\TLV((object) array('Class' => TLV_CLASS_UNIVERSAL, 'Type' => TLV_TYPE_CONSTRUCTED, 'Tag' => TLV_TAG_SEQUENCE)); $ocspRequest->add($tbsRequest); /* FIXME? we should should consider replacing the following code with argumentless constructor call and setting of the parmeters without the serialize-parse cycle */ $writer = \ASN1\ASN1::createWriter(); $ser = \ASN1\ASN1::createSerializer($writer); $data = $ser->serialize($ocspRequest); return new self($data); }
/** * Create a new \\PKIX\\TSP\\Request from parameters provided in * $params. The request is minimal but compliant with RFC3161 and * can be used to query a TSP server. * * @param array $params contains configuration parameters for the * message: * - hashAlgorithm - string representation of hash algorithm OID * - hashedMessage - hex representation of the hashed message * * @retval \PKIX\TSP\Request new instance */ public function createFromParams(array $params) { /* TimeStampReq ::= SEQUENCE { version INTEGER { v1(1) }, messageImprint MessageImprint, --a hash algorithm OID and the hash value of the data to be --time-stamped reqPolicy TSAPolicyId OPTIONAL, nonce INTEGER OPTIONAL, certReq BOOLEAN DEFAULT FALSE, extensions [0] IMPLICIT Extensions OPTIONAL } MessageImprint ::= SEQUENCE { hashAlgorithm AlgorithmIdentifier, hashedMessage OCTET STRING } */ $hashAlg = new \ASN1\TLV((object) array('Class' => TLV_CLASS_UNIVERSAL, 'Type' => TLV_TYPE_CONSTRUCTED, 'Tag' => TLV_TAG_SEQUENCE)); $algorithm = \ASN1\TLV\OID::create(); $algorithm->set($params['hashAlgorithm']); $parameters = \ASN1\TLV\Null::create(); $parameters->set(null); $hashAlg->add($algorithm); $hashAlg->add($parameters); $hashedMessage = \ASN1\TLV\OctetString::create(); $hashedMessage->set($params['hashedMessage']); $messageImprint = new \ASN1\TLV((object) array('Class' => TLV_CLASS_UNIVERSAL, 'Type' => TLV_TYPE_CONSTRUCTED, 'Tag' => TLV_TAG_SEQUENCE)); $messageImprint->add($hashAlg); $messageImprint->add($hashedMessage); $version = \ASN1\TLV\Integer::create(); $version->set(static::TSP_Version); $tsReq = new \ASN1\TLV((object) array('Class' => TLV_CLASS_UNIVERSAL, 'Type' => TLV_TYPE_CONSTRUCTED, 'Tag' => TLV_TAG_SEQUENCE)); $tsReq->add($version); $tsReq->add($messageImprint); $writer = \ASN1\ASN1::createWriter(); $ser = \ASN1\ASN1::createSerializer($writer); $data = $ser->serialize($tsReq); return new static($data); }