Skip to content

Commit 57346da

Browse files
Moussa Sidibesidibos
authored andcommitted
SDK-603: Amend the Anchor converter to look for known Oids
1 parent e7d09fc commit 57346da

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

sandbox/src/Http/RequestBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,17 @@ private function addAttribute(SandboxAttribute $attribute)
198198
private function formatAnchors(array $anchors)
199199
{
200200
$anchorsList = [];
201+
$tsMultiplier = 1000000;
201202
foreach ($anchors as $anchor) {
202203
/** @var SandboxAnchor $anchor */
203204
if (!($anchor instanceof SandboxAnchor)) {
204205
continue;
205206
}
206207
$anchorsList[] = [
207-
'type' => $anchor->getType(),
208+
'type' => strtoupper($anchor->getType()),
208209
'value' => $anchor->getValue(),
209210
'sub_type' => $anchor->getSubtype(),
210-
'timestamp' => $anchor->getTimestamp()
211+
'timestamp' => (int) $anchor->getTimestamp() * $tsMultiplier
211212
];
212213
}
213214
return $anchorsList;

src/Yoti/Util/Profile/AnchorConverter.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,38 @@ public static function convert(Anchor $protobufAnchor)
2525
$anchorSubType = $protobufAnchor->getSubType();
2626
$yotiSignedTimeStamp = self::convertToYotiSignedTimestamp($protobufAnchor);
2727
$X509CertsList = self::convertCertsListToX509($X509, $protobufAnchor->getOriginServerCerts());
28+
$anchorTypesMap = self::getAnchorTypesMap();
2829

2930
foreach ($X509CertsList as $certX509Obj) {
3031
$certExtArr = $certX509Obj->tbsCertificate->extensions;
3132

32-
if (count($certExtArr) > 1) {
33-
$oid = $certExtArr[1]->extnId;
34-
$anchorType = self::getAnchorTypeByOid($oid);
35-
$extEncodedValue = $certExtArr[1]->extnValue;
36-
37-
if ($decodedAnchorValue = self::decodeAnchorValue($ASN1, $X509, $extEncodedValue)) {
38-
$yotiAnchor = self::createYotiAnchor(
39-
$decodedAnchorValue,
40-
$anchorType,
41-
$anchorSubType,
42-
$yotiSignedTimeStamp,
43-
$X509CertsList
44-
);
45-
$anchorMap = [
46-
'oid' => $oid,
47-
'yoti_anchor' => $yotiAnchor
48-
];
49-
// We are only looking for one YotiAnchor from protobufAnchor
50-
break;
33+
foreach($anchorTypesMap as $oid => $anchorType)
34+
{
35+
foreach($certExtArr as $extObj) {
36+
$extRaw = (array) $extObj;
37+
$oidFound = array_search($oid, $extRaw, TRUE);
38+
if ($oidFound !== FALSE) {
39+
$extEncodedValue = $extRaw['extnValue'];
40+
41+
if (
42+
is_string($extEncodedValue)
43+
&& ($decodedAnchorValue = self::decodeAnchorValue($ASN1, $X509, $extEncodedValue))
44+
) {
45+
$yotiAnchor = self::createYotiAnchor(
46+
$decodedAnchorValue,
47+
$anchorType,
48+
$anchorSubType,
49+
$yotiSignedTimeStamp,
50+
$X509CertsList
51+
);
52+
$anchorMap = [
53+
'oid' => $oid,
54+
'yoti_anchor' => $yotiAnchor
55+
];
56+
// We are only looking for one YotiAnchor from protobufAnchor
57+
break;
58+
}
59+
}
5160
}
5261
}
5362
}

0 commit comments

Comments
 (0)