> For the complete documentation index, see [llms.txt](https://ajuda.rnp.br/cafe/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ajuda.rnp.br/cafe/sheerid/adesao-sp/geracao-de-chave-e-certificado.md).

# Geração de Chave e Certificado

Este tutorial apresenta os passos necessários para se fazer a geração de Chave e Certificado SSL.A seguir serão apresentados os requisitos bem como roteiro para a referida instalação.

## Criando certificados csr e key

Substituir o termo {exemplo.rnp.br} pelo nome do seu host de aplicação, por exemplo:

```
{exemplo.rnp.br} = aplicacao-servico.rnp.br
```

```bash
openssl req -new -newkey rsa:4096 \
-nodes -out /etc/ssl/certs/{exemplo.rnp.br}.csr \
-keyout /etc/ssl/private/{exemplo.rnp.br}.key \
-subj "/C=BR/ST=Rio de Janeiro/L=Rio de Janeiro/O=Rede Nacional de Ensino e Pesquisa/OU=RNP/CN={exemplo.rnp.br}"
```

## Criando certificado crt

```bash
openssl x509 \
-req -days 730 \
-in  /etc/ssl/certs/{exemplo.rnp.br}.csr \
-signkey /etc/ssl/private/{exemplo.rnp.br}.key \
-out /etc/ssl/certs/{exemplo.rnp.br}.crt
```

## Permissao para os arquivo

```bash
chmod 644 /etc/ssl/private/{exemplo.rnp.br}.key
chmod 644 /etc/ssl/certs/{exemplo.rnp.br}.crt
```

## Imprimindo certificados para envio ao MOKA da CAFe

```bash
cat /etc/ssl/certs/{exemplo.rnp.br}.crt
```

O resultado irá aparecer na tela, copie APENAS os valores que irão aparecer entre as TAGs&#x20;

\-----BEGIN CERTIFICATE-----

\-----END CERTIFICATE-----

Após copiar esse valor substitua no arquivo de metadado aonde aparecer as TAGs

```
INSIRA_AQUI_O_CONTEUDO_DO_ARQUIVO_DO_CERTIFICADO
```

## Metadado do SP gerado manualmente

Legenda

Substituir $HOSTNAME, $NOME\_SERVICO, $SIGLA\_SERVICO, $DESCRICAO\_SERVICO, $URL\_SERVICO, $CONTATO e $EMAIL\_CONTATO

```xml
<EntityDescriptor entityID="https://$HOSTNAME/shibboleth-sp2">
 <SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol urn:oasis:names:tc:SAML:1.1:protocol urn:oasis:names:tc:SAML:1.0:protocol">
 <Extensions>
 <mdui:UIInfo xmlns:mdui="urn:oasis:names:tc:SAML:metadata:ui">
 <mdui:DisplayName xml:lang="en">$SIGLA_SERVICO - $NOME_SERVICO</mdui:DisplayName>
 <mdui:Description xml:lang="en">$DESCRICAO_SERVICO.</mdui:Description>
 </mdui:UIInfo>
 </Extensions>
 <KeyDescriptor>
 <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
 <ds:X509Data>
 <ds:X509Certificate>
INSIRA_AQUI_O_CONTEUDO_DO_ARQUIVO_DO_CERTIFICADO
INSIRA_AQUI_O_CONTEUDO_DO_ARQUIVO_DO_CERTIFICADO
INSIRA_AQUI_O_CONTEUDO_DO_ARQUIVO_DO_CERTIFICADO
 </ds:X509Certificate>
 </ds:X509Data>
 </ds:KeyInfo>
 </KeyDescriptor>
 <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://$HOSTNAME/Shibboleth.sso/SAML2/POST" index="1"/>
 <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign" Location="https://$HOSTNAME/Shibboleth.sso/SAML2/POST-SimpleSign" index="2"/>
 <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" Location="https://$HOSTNAME/Shibboleth.sso/SAML2/Artifact" index="3"/>
 <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:PAOS" Location="https://$HOSTNAME/Shibboleth.sso/SAML2/ECP" index="4"/>
 <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:1.0:profiles:browser-post" Location="https://$HOSTNAME/Shibboleth.sso/SAML/POST" index="5"/>
 <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:1.0:profiles:artifact-01" Location="https://$HOSTNAME/Shibboleth.sso/SAML/Artifact" index="6"/>
 </SPSSODescriptor>
 <Organization>
 <OrganizationName xml:lang="en">$SIGLA_SERVICO - $NOME_SERVICO</OrganizationName>
 <OrganizationDisplayName xml:lang="en">$SIGLA_SERVICO - $NOME_SERVICO</OrganizationDisplayName>
 <OrganizationURL xml:lang="en">http://$URL_SERVICO</OrganizationURL>
 </Organization>
 <ContactPerson contactType="technical">
 <SurName>$CONTATO</SurName>
 <EmailAddress>$EMAIL_CONTATO</EmailAddress>
 </ContactPerson>
</EntityDescriptor>
```

Pronto ao final salve suas modificações no arquivo e envie o metadado para a equipe de operação da CAFe GTI/RNP através de um chamado pelo nosso canal de atendimento.

Seu metadado será inserido na federação Chimarrão para homologação e se aprovado será migrado para a federação CAFe.

## Procedimento para atualização de certificado em um SP

## Encontrar onde estao os certificados

```bash
cat /etc/shibboleth/shibboleth2.xml
```

## Fazendo backup dos certificados atuais

```bash
mkdir /etc/ssl/private/bck && cp /etc/ssl/private/{antigo_certificado}.key /etc/ssl/private/bck
mkdir /etc/ssl/certs/bck && cp /etc/ssl/certs/{antigo_certificado}.crt /etc/ssl/certs/bck
```

## Removendo certificados atuais

```bash
rm /etc/ssl/private/{antigo_certificado}.key
rm /etc/ssl/certs/{antigo_certificado}.crt
```

Gerar um novo certificado, procedimento [acima](#criando-certificados-csr-e-key). Após gerar um novo certificado não esquecer de enviar o contéudo do novo certificado gerado para equipe de operação da CAFe GTI/RNP, pois o mesmo deverá ser substituído no MOKA da CAFe.

## Testando e resetando shibboleth

```bash
shibd -t
service shibd stop
service shibd start
service shibd status
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ajuda.rnp.br/cafe/sheerid/adesao-sp/geracao-de-chave-e-certificado.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
