   @spec find_by_name([Map.t], String.t) :: Map.t
   defp find_by_name(elems, name) do
     Enum.find(elems, fn (elem) -> elem["name"] == name end)
+  end
+
+  @spec get_cert(Map.t, String.t) :: binary
+  defp get_cert(%{"certificate-authority" => certfile}, basepath) do
+    cert_from_pem(certfile, basepath)
+  end
+
+  defp get_cert(%{"certificate-authority-data" => certdata}, _) do
+    cert_from_base64(certdata)
   end
 
   @spec auth_from_user(Map.t, String.t) :: auth_t

    %Kazan.Server.CertificateAuth{
      certificate: cert_from_pem(cert_file, basepath),
      key: private_key_from_pem(key_file, basepath)
    }
  end


    end)
  end

  defp cert_from_base64(nil), do: nil
  defp cert_from_base64(encoded_cert) do
    case Base.decode64(encoded_cert) do
      {:ok, cert_data} ->
          :public_key.pem_decode(cert_data)
            |> Enum.find_value(fn 
              {:Certificate, data, _} -> data
              _ -> nil
          end)
      _ -> nil
    end
  end

  @private_key_atoms [:RSAPrivateKey, :DSAPrivateKey, :ECPrivateKey, :PrivateKeyInfo]

  defp private_key_from_pem(nil, _), do: nil
