20 : body_size(0), state(kind == REPLY ? BEFORE_LENGTH: BEFORE_CODE)
25 char const *current_pos = buffer;
26 while (current_pos != buffer + len && state != END) {
41 if (
xisalnum(*current_pos) || *current_pos ==
'_') {
42 current_block += *current_pos;
48 current_block.clear();
49 state = BEFORE_LENGTH;
69 current_block += *current_pos;
74 body_size = atoi(current_block.c_str());
75 current_block.clear();
96 size_t body_len = (
static_cast<size_t>(buffer + len - current_pos) >= body_size - current_block.length())
97 ? body_size - current_block.length()
98 :
static_cast<size_t>(buffer + len - current_pos);
99 current_block += std::string(current_pos, body_len);
100 current_pos += body_len;
101 if (current_block.length() == body_size) {
102 body = current_block;
105 if (current_block.length() > body_size) {
116 if (state != END)
return INCOMPLETE;
130 if (code.empty())
return std::string();
131 return code +
' ' + std::to_string(body.length()) +
' ' + body;
140 current_block.clear();
147 std::string temp_body(body.c_str(), body.length());
148 char * buffer =
const_cast<char *
>(temp_body.c_str());
149 char * token = strtok(buffer,
"\r\n");
150 while (token !=
nullptr) {
151 std::string current_string(token);
152 size_t equal_pos = current_string.find(
'=');
153 if (equal_pos == std::string::npos) {
154 size_t offset_body_part = token - temp_body.c_str();
155 other_part = std::string(body.c_str() + offset_body_part, body.length() - offset_body_part);
158 std::string param(current_string.c_str(), current_string.c_str() + equal_pos);
159 std::string value(current_string.c_str() + equal_pos + 1);
160 map.insert(std::make_pair(param, value));
162 token = strtok(
nullptr,
"\r\n");
169 for (BodyParams::const_iterator i = map.begin(); i != map.end(); ++i) {
170 if (i != map.begin())
172 body += i->first +
"=" + i->second;
174 if (!other_part.empty())
175 body +=
'\n' + other_part;
182 std::string certs_part;
183 parseBody(map, certs_part);
185 if (i == map.end()) {
186 throw TextException(
"Cannot find \"host\" parameter in request message",
Here());
191 if (i != map.end() && strcasecmp(i->second.c_str(),
"on") == 0)
195 if (i != map.end() && strcasecmp(i->second.c_str(),
"on") == 0)
199 if (i != map.end()) {
207 if (i != map.end()) {
216 if (!(certProperties.
signHash = EVP_get_digestbyname(signHashName))) {
224 static const std::string CERT_BEGIN_STR(
"-----BEGIN CERTIFICATE");
226 if ((pos = certs_part.find(CERT_BEGIN_STR)) != std::string::npos) {
227 pos += CERT_BEGIN_STR.length();
228 if ((pos= certs_part.find(CERT_BEGIN_STR, pos)) != std::string::npos)
248 std::string certsPart;
255 body +=
"\n" + certsPart;
#define Here()
source code location of the caller
T * get() const
Returns raw and possibly nullptr pointer.
Security::PrivateKeyPointer signWithPkey
The key of the signing certificate.
Security::CertPointer signWithX509
Certificate to sign the generated request.
bool setCommonName
Replace the CN field of the mimicking subject with the given.
bool setValidAfter
Do not mimic "Not Valid After" field.
CertSignAlgorithm signAlgorithm
The signing algorithm to use.
bool setValidBefore
Do not mimic "Not Valid Before" field.
Security::CertPointer mimicCert
Certificate to mimic.
const EVP_MD * signHash
The signing hash to use.
std::string commonName
A CN to use for the generated certificate.
void setCode(std::string const &aCode)
Set new request/reply code to compose.
static const std::string param_SetCommonName
Parameter name for passing SetCommonName cert adaptation variable.
void clear()
Reset the class.
void composeBody(BodyParams const &map, std::string const &other_part)
void setBody(std::string const &aBody)
Set new body to encode.
static const std::string param_SignHash
The signing hash to use.
static const std::string param_SetValidBefore
Parameter name for passing SetValidBefore cert adaptation variable.
static const std::string param_SetValidAfter
Parameter name for passing SetValidAfter cert adaptation variable.
static const std::string code_new_certificate
String code for "new_certificate" messages.
CrtdMessage(MessageKind kind)
std::string const & getBody() const
Current body. If parsing is not finished the method returns incompleted body.
ParseResult
Parse result codes.
void parseBody(BodyParams &map, std::string &other_part) const
static const std::string param_host
Parameter name for passing hostname.
std::string const & getCode() const
Current response/request code. If parsing is not finished the method may return incompleted code.
ParseResult parse(const char *buffer, size_t len)
void parseRequest(CertificateProperties &)
orchestrates entire request parsing
std::map< std::string, std::string > BodyParams
static const std::string param_Sign
Parameter name for passing signing algorithm.
void composeRequest(Ssl::CertificateProperties const &)
std::string compose() const
an std::runtime_error with thrower location info
CertSignAlgorithm certSignAlgorithmId(const char *sg)
bool appendCertToMemory(Security::CertPointer const &cert, std::string &bufferToWrite)
bool writeCertAndPrivateKeyToMemory(Security::CertPointer const &cert, Security::PrivateKeyPointer const &pkey, std::string &bufferToWrite)
bool readCertAndPrivateKeyFromMemory(Security::CertPointer &cert, Security::PrivateKeyPointer &pkey, char const *bufferToRead)
const char * CertAdaptAlgorithmStr[]
const char * certSignAlgorithm(int sg)
Security::CertPointer ReadCertificate(const BIO_Pointer &)
BIO_Pointer ReadOnlyBioTiedTo(const char *)
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
#define SQUID_SSL_SIGN_HASH_IF_NONE