@@ -455,7 +455,7 @@ protected function processChain($target, $chain)
455455 );
456456 $ targetId = $ this ->db ->lastInsertId ();
457457 } else {
458- $ targetId = ( int ) $ row ->id ;
458+ $ targetId = $ row ->id ;
459459 }
460460
461461 $ chainUptodate = false ;
@@ -474,7 +474,7 @@ protected function processChain($target, $chain)
474474 ->getSelectBase ()
475475 ->where (new Expression (
476476 'certificate_link.certificate_chain_id = %d ' ,
477- [( int ) $ lastChain ->id ]
477+ [$ lastChain ->id ]
478478 ))
479479 ->orderBy ('certificate_link.order ' );
480480
@@ -523,13 +523,16 @@ protected function processChain($target, $chain)
523523 $ lastCertInfo [] = $ index ;
524524 }
525525
526- $ rootCa = X509Certificate::on ($ this ->db );
527- $ rootCa
526+ // There might be chains that do not include the self-signed top-level Ca,
527+ // so we need to include it manually here, as we need to display the full
528+ // chain in the UI.
529+ $ rootCa = X509Certificate::on ($ this ->db )
528530 ->columns (['id ' ])
529- ->filter (Filter::equal ('issuer_hash ' , $ lastCertInfo [1 ]))
530- ->filter (Filter::equal ('trusted ' , true ));
531+ ->filter (Filter::equal ('subject_hash ' , $ lastCertInfo [1 ]))
532+ ->filter (Filter::equal ('self_signed ' , true ))
533+ ->first ();
531534
532- if (( $ rootCa = $ rootCa -> first ()) && $ rootCa ->id !== $ lastCertInfo [0 ]) {
535+ if ($ rootCa && $ rootCa ->id !== $ lastCertInfo [0 ]) {
533536 $ this ->db ->update (
534537 'x509_certificate_chain ' ,
535538 ['length ' => count ($ chain ) + 1 ],
0 commit comments