コード例 #1
0
ファイル: AAControlsExtension.php プロジェクト: sop/x509
 protected static function _fromDER($data, $critical)
 {
     $seq = Sequence::fromDER($data);
     $path_len = null;
     $permitted = null;
     $excluded = null;
     $permit_unspecified = true;
     $idx = 0;
     if ($seq->has($idx, Element::TYPE_INTEGER)) {
         $path_len = $seq->at($idx++)->asInteger()->number();
     }
     if ($seq->hasTagged(0)) {
         $attr_seq = $seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE)->asSequence();
         $permitted = array_map(function (UnspecifiedType $el) {
             return $el->asObjectIdentifier()->oid();
         }, $attr_seq->elements());
         $idx++;
     }
     if ($seq->hasTagged(1)) {
         $attr_seq = $seq->getTagged(1)->asImplicit(Element::TYPE_SEQUENCE)->asSequence();
         $excluded = array_map(function (UnspecifiedType $el) {
             return $el->asObjectIdentifier()->oid();
         }, $attr_seq->elements());
         $idx++;
     }
     if ($seq->has($idx, Element::TYPE_BOOLEAN)) {
         $permit_unspecified = $seq->at($idx++)->asBoolean()->value();
     }
     return new self($critical, $path_len, $permitted, $excluded, $permit_unspecified);
 }
コード例 #2
0
 protected static function _fromDER($data, $critical)
 {
     $purposes = array_map(function (UnspecifiedType $el) {
         return $el->asObjectIdentifier()->oid();
     }, Sequence::fromDER($data)->elements());
     return new self($critical, ...$purposes);
 }
コード例 #3
0
 /**
  *
  * @param string $data
  * @param bool $critical
  * @return self
  */
 protected static function _fromDER($data, $critical)
 {
     $targets = array_map(function (UnspecifiedType $el) {
         return Targets::fromASN1($el->asSequence());
     }, Sequence::fromDER($data)->elements());
     return new self($critical, ...$targets);
 }
コード例 #4
0
 protected static function _fromDER($data, $critical)
 {
     $attribs = array_map(function (UnspecifiedType $el) {
         return Attribute::fromASN1($el->asSequence());
     }, Sequence::fromDER($data)->elements());
     if (!count($attribs)) {
         throw new \UnexpectedValueException("SubjectDirectoryAttributes must have at least one Attribute.");
     }
     return new self($critical, ...$attribs);
 }
コード例 #5
0
 protected static function _fromDER($data, $critical)
 {
     $policies = array_map(function (UnspecifiedType $el) {
         return PolicyInformation::fromASN1($el->asSequence());
     }, Sequence::fromDER($data)->elements());
     if (!count($policies)) {
         throw new \UnexpectedValueException("certificatePolicies must contain" . " at least one PolicyInformation.");
     }
     return new self($critical, ...$policies);
 }
コード例 #6
0
ファイル: PolicyMappingsExtension.php プロジェクト: sop/x509
 protected static function _fromDER($data, $critical)
 {
     $mappings = array_map(function (UnspecifiedType $el) {
         return PolicyMapping::fromASN1($el->asSequence());
     }, Sequence::fromDER($data)->elements());
     if (!count($mappings)) {
         throw new \UnexpectedValueException("PolicyMappings must have at least one mapping.");
     }
     return new self($critical, ...$mappings);
 }
コード例 #7
0
 protected static function _fromDER($data, $critical)
 {
     $dps = array_map(function (UnspecifiedType $el) {
         return DistributionPoint::fromASN1($el->asSequence());
     }, Sequence::fromDER($data)->elements());
     if (!count($dps)) {
         throw new \UnexpectedValueException("CRLDistributionPoints must have" . " at least one DistributionPoint.");
     }
     // late static bound, extended by Freshest CRL extension
     return new static($critical, ...$dps);
 }
コード例 #8
0
ファイル: NameConstraintsExtension.php プロジェクト: sop/x509
 protected static function _fromDER($data, $critical)
 {
     $seq = Sequence::fromDER($data);
     $permitted = null;
     $excluded = null;
     if ($seq->hasTagged(0)) {
         $permitted = GeneralSubtrees::fromASN1($seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
     }
     if ($seq->hasTagged(1)) {
         $excluded = GeneralSubtrees::fromASN1($seq->getTagged(1)->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
     }
     return new self($critical, $permitted, $excluded);
 }
コード例 #9
0
 protected static function _fromDER($data, $critical)
 {
     $seq = Sequence::fromDER($data);
     $require_explicit_policy = null;
     $inhibit_policy_mapping = null;
     if ($seq->hasTagged(0)) {
         $require_explicit_policy = $seq->getTagged(0)->asImplicit(Element::TYPE_INTEGER)->asInteger()->number();
     }
     if ($seq->hasTagged(1)) {
         $inhibit_policy_mapping = $seq->getTagged(1)->asImplicit(Element::TYPE_INTEGER)->asInteger()->number();
     }
     return new self($critical, $require_explicit_policy, $inhibit_policy_mapping);
 }
コード例 #10
0
 protected static function _fromDER($data, $critical)
 {
     $seq = Sequence::fromDER($data);
     $ca = false;
     $path_len = null;
     $idx = 0;
     if ($seq->has($idx, Element::TYPE_BOOLEAN)) {
         $ca = $seq->at($idx++)->asBoolean()->value();
     }
     if ($seq->has($idx, Element::TYPE_INTEGER)) {
         $path_len = $seq->at($idx)->asInteger()->number();
     }
     return new self($critical, $ca, $path_len);
 }
コード例 #11
0
 protected static function _fromDER($data, $critical)
 {
     $seq = Sequence::fromDER($data);
     $keyIdentifier = null;
     $issuer = null;
     $serial = null;
     if ($seq->hasTagged(0)) {
         $keyIdentifier = $seq->getTagged(0)->asImplicit(Element::TYPE_OCTET_STRING)->asOctetString()->string();
     }
     if ($seq->hasTagged(1) || $seq->hasTagged(2)) {
         if (!$seq->hasTagged(1) || !$seq->hasTagged(2)) {
             throw new \UnexpectedValueException("AuthorityKeyIdentifier must have both" . " authorityCertIssuer and authorityCertSerialNumber" . " present or both absent.");
         }
         $issuer = GeneralNames::fromASN1($seq->getTagged(1)->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
         $serial = $seq->getTagged(2)->asImplicit(Element::TYPE_INTEGER)->asInteger()->number();
     }
     return new self($critical, $keyIdentifier, $issuer, $serial);
 }
コード例 #12
0
ファイル: ECDSASigValue.php プロジェクト: sop/crypto-util
 /**
  * Initialize from DER.
  *
  * @param string $data
  * @return self
  */
 public static function fromDER($data)
 {
     return self::fromASN1(Sequence::fromDER($data));
 }
コード例 #13
0
 protected static function _fromDER($data, $critical)
 {
     return new self($critical, GeneralNames::fromASN1(Sequence::fromDER($data)));
 }
コード例 #14
0
 /**
  * Decrypt PrivateKeyInfo from the encrypted data.
  *
  * @param string $password
  * @param Crypto $crypto
  * @return PrivateKeyInfo
  */
 public function decryptPrivateKeyInfo($password, Crypto $crypto)
 {
     try {
         $scheme = PBEScheme::fromAlgorithmIdentifier($this->_algo, $crypto);
         $data = $scheme->decrypt($this->_data, $password);
         return PrivateKeyInfo::fromASN1(Sequence::fromDER($data));
     } catch (\RuntimeException $e) {
         throw new \RuntimeException("Failed to decrypt private key.", 0, $e);
     }
 }