#NEWLINE# @ flow . StateHandler ( next_state = 'End' ) #NEWLINE# def Start( self ) : #NEWLINE# #INDENT# 'Sign the CSR from the client.' #NEWLINE# client = aff4 . FACTORY . Create ( self . client_id , 'VFSGRRClient' , mode = 'rw' , token = self . token ) #NEWLINE# if ( self . args . csr . type != rdf_crypto . Certificate . Type . CSR ) : #NEWLINE# #INDENT# raise IOError ( 'Must be called with CSR' ) #NEWLINE# #UNINDENT# req = X509 . load_request_string ( self . args . csr . pem ) #NEWLINE# if ( req . verify ( req . get_pubkey ( ) ) != 1 ) : #NEWLINE# #INDENT# raise flow . FlowError ( ( 'CSR for client %s did not verify: %s' % ( self . client_id , req . as_pem ( ) ) ) ) #NEWLINE# #UNINDENT# public_key = req . get_pubkey ( ) . get_rsa ( ) . pub ( ) [ 1 ] #NEWLINE# self . cn = rdf_client . ClientURN . FromPublicKey ( public_key ) #NEWLINE# if ( self . cn != rdf_client . ClientURN ( req . get_subject ( ) . CN ) ) : #NEWLINE# #INDENT# raise IOError ( ( 'CSR CN %s does not match public key %s.' % ( rdf_client . ClientURN ( req . get_subject ( ) . CN ) , self . cn ) ) ) #NEWLINE# #UNINDENT# logging . info ( 'Will sign CSR for: %s' , self . cn ) #NEWLINE# cert = self . MakeCert ( self . cn , req ) #NEWLINE# if ( req . cn != self . client_id ) : #NEWLINE# #INDENT# raise flow . FlowError ( 'Certificate name %s mismatch for client %s' , self . cn , self . client_id ) #NEWLINE# #UNINDENT# certificate_attribute = rdf_crypto . RDFX509Cert ( cert . as_pem ( ) ) #NEWLINE# client . Set ( client . Schema . CERT , certificate_attribute ) #NEWLINE# client . Set ( client . Schema . FIRST_SEEN , rdfvalue . RDFDatetime ( ) . Now ( ) ) #NEWLINE# index = aff4 . FACTORY . Create ( client_index . MAIN_INDEX , aff4_type = 'ClientIndex' , object_exists = True , mode = 'rw' , token = self . token ) #NEWLINE# index . AddClient ( client ) #NEWLINE# client . Close ( sync = True ) #NEWLINE# self . Publish ( 'ClientEnrollment' , certificate_attribute . common_name ) #NEWLINE# self . Log ( 'Enrolled %s successfully' , self . client_id )