0

Here is the working script with hard coded values:

$subject->currentCert['tbsCertificate']['extensions'][] = array(
   'extnId' => 'id-ce-subjectAltName',
   'critical' => false,
   'extnValue' => array(
      array('dNSName' => 'www.domain1.com'),
      array('dNSName' => 'www.domain2.com')
   )
);

I would like to update the above script (extnValue section only) to automatically take values from a another array called $OPTIONS["altnames"]

First I convert the following string to an array

$sans = 'www.domain1.com, www.domain2.com';

I converted the string to an array $OPTIONS["altnames"] with the following code:

$OPTIONS["altnames"] = array();
if (    !empty($sans)   ) {
    if (strpos($sans,",") !== false) {
        $sans = str_replace(" ", "", $sans); //remove spaces
        $sans = explode(",", $sans); //strip each value after comma to array

        foreach ($sans as $value) {
        array_push($OPTIONS["altnames"], $value);
        }
    }
}

Not sure what to do next

4
  • What's wrong with just $OPTIONS['altnames'] = $sans;? Commented Sep 18, 2015 at 17:04
  • I guess you are looking for the array_merge() function? php.net/manual/en/function.array-merge.php Commented Sep 18, 2015 at 17:05
  • Get rid of the strpos() check. What if $sans just has one name with no comma, don't you want to put that into the options? Commented Sep 18, 2015 at 17:06
  • @barmar, yes i do want to add it.. ultimately, i want to be able to port over any values in $OPTIONS array to 'extnValue' array in this format array('dNSName' => 'www.domain1.com'), Commented Sep 18, 2015 at 17:08

1 Answer 1

1

You need to add another level of array in the extnValue array when you copy it from $OPTIONS['altnames']:

$extnValues = array();
foreach ($OPTIONS['altnames'] AS $name) {
    $extnValues[] = array('dNSName' => $name);
}
$subject->currentCert['tbsCertificate']['extensions'][] = array(
   'extnId' => 'id-ce-subjectAltName',
   'critical' => false,
   'extnValue' => $extnValues
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.