---
name: "globus_gsi_cred_read_key"
section: "3"
platform: "linux"
package: "libglobus-gsi-credential-doc"
version: "8.4-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/globus_gsi_cred_operations"
---

# globus\_gsi\_cred\_read\_key(3)

Credential Operations - Credential Operations.

Part of [globus\_gsi\_cred\_operations(3)](/globus_gsi_cred_operations/3.md).

## NAME

globus\_gsi\_cred\_operations - Credential Operations

 \- Credential Operations.

## SYNOPSIS

### Functions

globus\_result\_t **globus\_gsi\_cred\_read** (**globus\_gsi\_cred\_handle\_t** handle, X509\_NAME \*desired\_subject)\
 Read a credential.  globus\_result\_t **globus\_gsi\_cred\_read\_proxy** (**globus\_gsi\_cred\_handle\_t** handle, const char \*proxy\_filename)\
 Read proxy credential.  globus\_result\_t **globus\_gsi\_cred\_read\_proxy\_bio** (**globus\_gsi\_cred\_handle\_t** handle, BIO \*bio)\
 Read proxy credential from a BIO.  globus\_result\_t **globus\_gsi\_cred\_read\_key** (**globus\_gsi\_cred\_handle\_t** handle, const char \*key\_filename, pem\_password\_cb \*pw\_cb)\
 Read a private key.  globus\_result\_t **globus\_gsi\_cred\_read\_cert** (**globus\_gsi\_cred\_handle\_t** handle, const char \*cert\_filename)\
 Read a certificate chain from a file.  globus\_result\_t **globus\_gsi\_cred\_read\_cert\_bio** (**globus\_gsi\_cred\_handle\_t** handle, BIO \*bio)\
 Read a certificate chain from a BIO.  globus\_result\_t **globus\_gsi\_cred\_read\_cert\_buffer** (const char \*pem\_buf, **globus\_gsi\_cred\_handle\_t** \*out\_handle, X509 \*\*out\_cert, STACK\_OF(X509) \*\*out\_cert\_chain, char \*\*out\_subject)\
 Read certificate chain from a buffer.  globus\_result\_t **globus\_gsi\_cred\_read\_pkcs12** (**globus\_gsi\_cred\_handle\_t** handle, const char \*pkcs12\_filename)\
 Read certificate and key from a PKCS12 file.  globus\_result\_t **globus\_gsi\_cred\_write** (**globus\_gsi\_cred\_handle\_t** handle, BIO \*bio)\
 Write Credential.  globus\_result\_t **globus\_gsi\_cred\_write\_proxy** (**globus\_gsi\_cred\_handle\_t** handle, const char \*proxy\_filename)\
 Write a proxy credential.  globus\_result\_t **globus\_gsi\_cred\_get\_cert\_type** (**globus\_gsi\_cred\_handle\_t** handle, globus\_gsi\_cert\_utils\_cert\_type\_t \*type)\
 Get the X.509 certificate type.

## Detailed Description

Credential Operations.

Read/Write a GSI Credential Handle.

This section defines operations to read and write GSI Credential handles.

## Function Documentation

### globus\_result\_t globus\_gsi\_cred\_get\_cert\_type (globus\_gsi\_cred\_handle\_t handle, globus\_gsi\_cert\_utils\_cert\_type\_t \* type)

Get the X.509 certificate type. Determine the type of the given X509 certificate For the list of possible values returned, see globus\_gsi\_cert\_utils\_cert\_type\_t.

**Parameters**

*handle* The credential handle containing the certificate \
 *type* The returned X509 certificate type

**Returns**

GLOBUS\_SUCCESS or an error captured in a globus\_result\_t

### globus\_result\_t globus\_gsi\_cred\_read (globus\_gsi\_cred\_handle\_t handle, X509\_NAME \* desired\_subject)

Read a credential. Read a credential from a filesystem location. The credential to read will be determined by the search order specified in the handle attributes. \

**Parameters**

*handle* The credential handle to set. This credential handle should already be initialized using globus\_gsi\_cred\_handle\_init. \
 *desired\_subject* The subject to check for when reading in a credential. The desired\_subject should be either a exact match of the read cert's subject or should just contain the /CN entry. If null, the credential read in is the first match based on the system configuration (paths and environment variables)

**Returns**

GLOBUS\_SUCCESS if no errors occurred, otherwise, an error object identifier is returned.

**See also**

**globus\_gsi\_cred\_read\_proxy()**

globus\_gsi\_cred\_read\_cert\_and\_key()

**Note**

This function always searches for the desired credential. If you don't want to perform a search, then don't use this function. The search goes in the order of the handle attributes' search order.

### globus\_result\_t globus\_gsi\_cred\_read\_cert (globus\_gsi\_cred\_handle\_t handle, const char \* cert\_filename)

Read a certificate chain from a file. Read a cert from a file. Cert should be in PEM format. Will also read additional certificates as chain if present.

**Parameters**

*handle* the handle to set based on the certificate that is read \
 *cert\_filename* the filename of the certificate to read

**Returns**

GLOBUS\_SUCCESS or an error object identifier

### globus\_result\_t globus\_gsi\_cred\_read\_cert\_bio (globus\_gsi\_cred\_handle\_t handle, BIO \* bio)

Read a certificate chain from a BIO. Read a cert from a BIO. Cert should be in PEM format. Will also read additional certificates as chain if present.

**Parameters**

*handle* the handle to set based on the certificate that is read \
 *bio* the bio to read the certificate from

**Returns**

GLOBUS\_SUCCESS or an error object identifier

### globus\_result\_t globus\_gsi\_cred\_read\_cert\_buffer (const char \* pem\_buf, globus\_gsi\_cred\_handle\_t \* out\_handle, X509 \*\* out\_cert, STACK\_OF(X509) \*\* out\_cert\_chain, char \*\* out\_subject)

Read certificate chain from a buffer. Read a cert from a buffer. Cert should be in PEM format. Will also read additional certificates as chain if present. Any parameter besides pem\_buf may be NULL.

**Parameters**

*pem\_buf* The buffer containing the PEM formatted cert and chain. \
 *out\_handle* The handle to initialize and set cert on. \
 *out\_cert* The X509 certificate. This should be freed with X509\_free(). \
 *out\_cert\_chain* The X509 certificate chain. This should be freed with sk\_X509\_free(). \
 *out\_subject* The identity name of the cert. This should be freed with OPENSSL\_free().

**Returns**

GLOBUS\_SUCCESS or an error object identifier

### globus\_result\_t globus\_gsi\_cred\_read\_key (globus\_gsi\_cred\_handle\_t handle, const char \* key\_filename, pem\_password\_cb \* pw\_cb)

Read a private key. Read a key from a PEM file.

**Parameters**

*handle* the handle to set based on the key that is read \
 *key\_filename* the filename of the key to read \
 *pw\_cb* the callback for obtaining a password for decrypting the key.

**Returns**

GLOBUS\_SUCCESS or an error object identifier

### globus\_result\_t globus\_gsi\_cred\_read\_pkcs12 (globus\_gsi\_cred\_handle\_t handle, const char \* pkcs12\_filename)

Read certificate and key from a PKCS12 file. Read a cert and key from a file. The file should be in PKCS12 format.

**Parameters**

*handle* the handle to populate with the read credential \
 *pkcs12\_filename* the filename containing the credential to read

**Returns**

GLOBUS\_SUCCESS or an error object identifier

### globus\_result\_t globus\_gsi\_cred\_read\_proxy (globus\_gsi\_cred\_handle\_t handle, const char \* proxy\_filename)

Read proxy credential. Read a proxy from a PEM file.

**Parameters**

*handle* The credential handle to set based on the proxy credential read from the file \
 *proxy\_filename* The file containing the proxy credential

**Returns**

GLOBUS\_SUCCESS or an error object identifier

### globus\_result\_t globus\_gsi\_cred\_read\_proxy\_bio (globus\_gsi\_cred\_handle\_t handle, BIO \* bio)

Read proxy credential from a BIO. Read a Proxy Credential from a BIO stream and set the credential handle to represent the read credential. The values read from the stream, in order, will be the signed certificate, the private key, and the certificate chain.

**Parameters**

*handle* The credential handle to set. The credential should handle be initialized (i.e. not NULL). \
 *bio* The stream to read the credential from

**Returns**

GLOBUS\_SUCCESS unless an error occurred, in which case an error object is returned

### globus\_result\_t globus\_gsi\_cred\_write (globus\_gsi\_cred\_handle\_t handle, BIO \* bio)

Write Credential. Write out a credential to a BIO. The credential parameters written, in order, are the signed certificate, the RSA private key, and the certificate chain (a set of X509 certificates). the credential is written out in PEM format.

**Parameters**

*handle* The credential to write out \
 *bio* The BIO stream to write out to

**Returns**

GLOBUS\_SUCCESS unless an error occurred, in which case an error object ID is returned.

### globus\_result\_t globus\_gsi\_cred\_write\_proxy (globus\_gsi\_cred\_handle\_t handle, const char \* proxy\_filename)

Write a proxy credential. Write out a credential to a file. The credential parameters written, in order, are the signed certificate, the RSA private key, and the certificate chain (a set of X509 certificates). the credential is written out in PEM format.

**Parameters**

*handle* The credential to write out \
 *proxy\_filename* The file to write out to

**Returns**

GLOBUS\_SUCCESS unless an error occurred, in which case an error object ID is returned.

## Author

Generated automatically by Doxygen for globus\_gsi\_credential from the source code.
