- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 openssl 用 c 编写 Apple 推送通知服务器提供程序(APNS 提供程序)。
到目前为止,我已经能够通过 ssl_write 成功发送通知,但有时可能会发生我发送的消息被拒绝的情况(无论出于何种原因,错误的 token 等......)。当发生这种情况并且我尝试 ssl_write 时,我会写入 -1 个字节,然后 APNS 应该发回错误消息并关闭连接。
该错误以二进制形式出现,由 6 个字节组成,如 Apple 文档中所述:Apple Documenatation
const int written= SSL_write(this->_ssl, buffer, bufferSize);
int want =SSL_want(this->_ssl);
if(want == 2 ){ //2 means that ssl wants to read
char bufferRead[6];
SSL_read(this->_ssl,bufferRead,6);
//Some code that transfers bufferRead into a ASCII format
}
我想问你,如何将这个二进制 bufferRead 转换为我可以读取并存储在 char* 或 std::string 中的内容。转换后的输出应类似于“881234”...
我很感激我能得到的任何帮助。
Eran 编辑解决方案:
unsigned char command = bufferRead[0];
unsigned char status = bufferRead[1];
unsigned char c2 = bufferRead[2];
unsigned char c3 = bufferRead[3];
unsigned char c4 = bufferRead[4];
unsigned char c5 = bufferRead[5];
int comInt = command;
int statusInt = status;
int id = (c5 << 24) +
(c4 << 16) +
(c3 << 8) +
(c2);
最佳答案
您应该将缓冲区解析为 3 个参数。自从我用 c 编程以来已经有一段时间了,但我认为你需要这样的东西:
char command = bufferRead[0]; // should contain 8
char status = bufferRead[1]; // the type of the error - the most common being 8 (InvalidToken)
int id = (bufferRead[2] << 24) +
(bufferRead[3] << 16) +
(bufferRead[4] << 8) +
(bufferRead[5]);
关于c - openssl ssl_read 将读取的二进制数据发送到 char*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20524179/
我正在寻找通过 HTTPS 从服务器下载或读取文件,并且我正在使用 openSSL。 我看到连接成功,但是 SSL_read()返回 0。SSL_get_error()返回 6 表示 SSL_ERRO
我正在尝试通过 SSL 连接到安全服务,但是在下面的代码中,SSL_read 永远不会返回,如果服务器不返回任何消息,这当然是正常行为,但是我尝试连接的服务器应该返回某种消息。以下内容是否有不允许阅读
考虑以下代码,它显示了尝试从 ssl 连接读取 buff_size 字节的尝试。 int bytes = SSL_read(m_ssl, buf, buff_size); int err = SSL_
我正在尝试使用 SSL_read 从 Openssl 链接套接字读取数据。我在客户端模式下执行 Openssl 操作,发送命令并从真实世界的服务器接收数据。我使用了两个线程,其中一个线程处理所有 Op
我有一个使用 ssl 的 openssl 客户端。客户端之前正在与 openssl 服务器通信,一切都很好。我们现在正在用 Java 重写服务器,我们看到发生了以下情况。 1) 连接到服务器 WORK
我正在获得随机字节来领导每个SSL_read缓冲区中的内容 char *getJSON(char *url) { int sock, length, bytes, https = 0;
当前的 OpenSSL 版本是 1.1.1d。 我正在使用 SSL 到 TCP 套接字。 以下是相关来源。 ... ... struct timeval tv; fd_set fdIn;
我正在读一本 openssl 编程 tutorial . 我不能让服务器应用程序在单个连接的任何操作上被阻止, 因此我将使用非 block 套接字。 看来,ssl 握手发生在 ssl_accept 和
我正在尝试将 OpenSSL 添加到 epoll 中,并且套接字处于非阻塞模式。令我困惑的一个问题是:由于 SSL 重新协商,SSL_read 可能会产生 SSL_ERROR_WANT_WRITE ,
我正在尝试编写一个连接到带有 OpenSSL 的服务器的 C++ 应用程序。我可以发送数据,它完好无损地到达服务器,但读取操作只读取 1 个字节。 代码: char* dest_u
我制作了一个服务器和一个客户端,它们在安全的 TLSv1.3、OpenSSL 3.0.0 channel 中进行通信。他们必须能够发送和接收,但在这个测试中,服务器只接收,客户端只定期发送应用程序数据
我是套接字编程的新手。 下面的代码片段用于从服务器获取大约 100 万行的响应。我不知道响应的确切长度,因此检查响应串是否包含结束词,如 OK、NO、SUCCESS、FAILURE 等。 size =
我有一个用C来处理ssl的程序,步骤如下: retval = select(maxfd + 1, &rfds, NULL, NULL, &tv); if (retval == -1) {
这个问题的答案可能是“取决于”,那么我的问题就变成了“它取决于什么?”以及“应该怎么做才能按顺序收到它们?”。 最佳答案 是的。 TLS 在保证流的字节顺序的 TCP 上运行,并且正如@dave_th
我正在编写一个使用 OpenSSL 进行连接的程序。除了一个选项外,使用阻塞套接字和线程一切正常: 我的线程 1 调用 SSL_read() 并等待它接收任何东西 - 但如果连接被合作伙伴关闭,SSL
我在 LogCat 中收到大量(一次数百条)消息: 07-15 21:24:48.096: D/NativeCrypto(1606): Doing SSL_Read() 07-15 21:24:48.
我正在编写一个 https 服务器。我已经创建了 csr 并使用我的测试域的根证书对其进行了签名。当客户端连接时,SSL_accept() 成功完成。我正在使用非阻塞 IO。因此,我将首先在 char
我有一个需要升级到 SSL 通信的客户端/服务器通信。目前我有一个发送和接收 tcp 数据的网络套接字。 客户端向服务器发出一个 tcp connect()。 服务器已经实现了接受部分,接受连接后服务
我正在尝试使用 openssl 用 c 编写 Apple 推送通知服务器提供程序(APNS 提供程序)。 到目前为止,我已经能够通过 ssl_write 成功发送通知,但有时可能会发生我发送的消息被拒
我正在尝试使用 OpenSSL 创建一个非阻塞套接字,这样我就可以遍历 SSL_read() 直到没有更多数据剩余,然后中断循环。经过大量工作,我终于使连接正常工作,但现在对于前一千多次迭代,SSL_
我是一名优秀的程序员,十分优秀!