def GetClientId(writeback_file): """Given the path to a client's writeback file, returns its client id.""" with open(writeback_file) as f: parsed_yaml = yaml.safe_load(f.read()) or {} serialized_pkey = parsed_yaml.get("Client.private_key", None) if serialized_pkey is None: raise PrivateKeyNotFoundException pkey = rdf_crypto.RSAPrivateKey(serialized_pkey) client_urn = comms.ClientCommunicator(private_key=pkey).common_name return re.compile(r"^aff4:/").sub("", client_urn.SerializeToString())
def testEnrollingCommunicator(self): """Test that the ClientCommunicator generates good keys.""" self.client_communicator = comms.ClientCommunicator() self.client_communicator.LoadServerCertificate( self.server_certificate, config.CONFIG["CA.certificate"]) # Verify that the CN is of the correct form csr = self.client_communicator.GetCSR() cn = rdf_client.ClientURN.FromPublicKey(csr.GetPublicKey()) self.assertEqual(cn, csr.GetCN())
def setUp(self): """Set up communicator tests.""" super(ClientCommsTest, self).setUp() # These tests change the config so we preserve state. config_stubber = test_lib.PreserveConfig() config_stubber.Start() self.addCleanup(config_stubber.Stop) self.client_private_key = config.CONFIG["Client.private_key"] self.server_certificate = config.CONFIG["Frontend.certificate"] self.server_private_key = config.CONFIG["PrivateKeys.server_key"] self.client_communicator = comms.ClientCommunicator( private_key=self.client_private_key) self.client_communicator.LoadServerCertificate( server_certificate=self.server_certificate, ca_certificate=config.CONFIG["CA.certificate"]) self.last_urlmock_error = None self._SetupCommunicator()
def ClientCertFromPrivateKey(self, private_key): communicator = comms.ClientCommunicator(private_key=private_key) csr = communicator.GetCSR() return rdf_crypto.RDFX509Cert.ClientCertFromCSR(csr)