From 4f508978c148c1c15de231ee8b5583cada77c150 Mon Sep 17 00:00:00 2001
From: "alexander.pace@ligo.org" <alexander.pace@ligo.org>
Date: Fri, 15 Nov 2019 12:49:22 -0600
Subject: [PATCH] Fixed decoding error in cert subjects

API requests on AWS were returning a 500 Server Error, traced it
down to a bytes vs string conversion when retrieving the certificate
subject
---
 gracedb/api/backends.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gracedb/api/backends.py b/gracedb/api/backends.py
index 9274ae56d..52252964f 100644
--- a/gracedb/api/backends.py
+++ b/gracedb/api/backends.py
@@ -221,6 +221,7 @@ class GraceDbX509FullCertAuthentication(GraceDbX509Authentication):
 
     def authenticate(self, request):
 
+        raise ValueError(request)
         # Make sure this request is directed to the API
         if self.api_only and not is_api_request(request.path):
             return None
@@ -298,19 +299,22 @@ class GraceDbX509FullCertAuthentication(GraceDbX509Authentication):
     @staticmethod
     def get_certificate_subject_string(certificate):
         subject = certificate.get_subject()
+        subject_decoded = [[word.decode("utf8") for word in sets]
+                for sets in subject.get_components()]
         subject_string = '/' + "/".join(["=".join(c) for c in
-            subject.get_components()])
+            subject_decoded])
         return subject_string
 
     @staticmethod
     def get_certificate_issuer_string(certificate):
         issuer = certificate.get_issuer()
+        issuer_decoded = [[word.decode("utf8") for word in sets]
+                for sets in issuer.get_components()]
         issuer_string = '/' + "/".join(["=".join(c) for c in
-            issuer.get_components()])
+            issuer_decoded])
         return issuer_string
 
 
-
 class GraceDbAuthenticatedAuthentication(authentication.BaseAuthentication):
     """
     If user is already authenticated by the main Django middleware,
-- 
GitLab