]> granicus.if.org Git - ejabberd/commitdiff
Don't crash on certificates without extensions (EJAB-1724)
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 23 Oct 2015 15:41:35 +0000 (18:41 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 23 Oct 2015 15:41:35 +0000 (18:41 +0300)
src/ejabberd_s2s.erl

index 9923eb121f5893d3704e6ad44080298e880ed9be..40179fe7dd4876456d69b767458e221a95c7d054 100644 (file)
@@ -620,10 +620,15 @@ get_s2s_state(S2sPid) ->
     [{s2s_pid, S2sPid} | Infos].
 
 get_cert_domains(Cert) ->
-    {rdnSequence, Subject} =
-       (Cert#'Certificate'.tbsCertificate)#'TBSCertificate'.subject,
-    Extensions =
-       (Cert#'Certificate'.tbsCertificate)#'TBSCertificate'.extensions,
+    TBSCert = Cert#'Certificate'.tbsCertificate,
+    Subject = case TBSCert#'TBSCertificate'.subject of
+                 {rdnSequence, Subj} -> lists:flatten(Subj);
+                 _ -> []
+             end,
+    Extensions = case TBSCert#'TBSCertificate'.extensions of
+                    Exts when is_list(Exts) -> Exts;
+                    _ -> []
+                end,
     lists:flatmap(fun (#'AttributeTypeAndValue'{type =
                                                    ?'id-at-commonName',
                                                value = Val}) ->
@@ -646,7 +651,7 @@ get_cert_domains(Cert) ->
                          end;
                      (_) -> []
                  end,
-                 lists:flatten(Subject))
+                 Subject)
       ++
       lists:flatmap(fun (#'Extension'{extnID =
                                          ?'id-ce-subjectAltName',