>

인증서 유효성 검사를 통과하여 로컬 서버에 연결하려고합니다. 서버에서 파싱하는 방법을 모른다는 이상한 응답 메시지가 표시됩니다.

서버와 같은 Wi-Fi에 있으며 터미널에서 응답을받을 수 있습니다

openssl s_client -connect 18.21.19.162:9000

NSStreamSocketSecurityLevelKey에 대해 다른 보안 수준을 설정하려고했습니다. SSLSettings에 다른 값을 추가하려고 시도했습니다.

-(void)setSSL
{
    NSLog(@"setting SSL");
    NSDictionary *sslSettings = [ [NSDictionary alloc]initWithObjectsAndKeys:
                                 [NSNumber numberWithBool:NO], kCFStreamSSLValidatesCertificateChain,
                                 [NSNumber numberWithBool:NO], kCFStreamSSLIsServer,
                                 nil ];
    CFReadStreamSetProperty((CFReadStreamRef)inputStream,kCFStreamPropertySSLSettings, (CFTypeRef)sslSettings);
    CFWriteStreamSetProperty((CFWriteStreamRef)outputStream, kCFStreamPropertySSLSettings, (CFTypeRef)sslSettings);
}
- (void)open {
    NSLog(@"Opening streams.");
    outputStream = (__bridge NSOutputStream *)writeStream;
    inputStream = (__bridge NSInputStream *)readStream;
    [outputStream setDelegate:self];
    [inputStream setDelegate:self];
    [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [inputStream setProperty:NSStreamSocketSecurityLevelTLSv1 forKey:NSStreamSocketSecurityLevelKey];
    [outputStream open];
    [inputStream open];
    NSLog(@"connected");
}
- (IBAction)connectBtnEvent:(id)sender {
   NSString *ip = @"18.21.19.162";
   NSString *port = @"9000";
    NSLog(@"Setting up connection to %@ : %i", ip, [port intValue]);
    CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef) ip, [port intValue], &readStream, &writeStream);
    [self open];
}
- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
    NSLog(@"stream event %lu", streamEvent);
    receivedData = @"";
    switch (streamEvent) {
        case NSStreamEventOpenCompleted:
        {
            NSLog(@"Stream opened");
            [self setSSL];
        }
            break;
        case NSStreamEventHasBytesAvailable:
        {
            //Trust object is available here
            NSLog(@"has byte available");
            if (theStream == inputStream)
            {
                uint8_t buffer[2048];
                NSInteger len;
                while ([inputStream hasBytesAvailable])
                {
                    len = [inputStream read:buffer maxLength:sizeof(buffer)];
                    if (len > 0)
                    {
                       NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
                       // NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSUTF8StringEncoding];
                        if(receivedData == nil || receivedData.length == 0)
                        {
                            receivedData = output;
                        }
                        else
                        {
                            receivedData = [receivedData stringByAppendingString:output];
                        }
                        if (output != nil)
                        {
                            NSLog(@"server said: %@", output);
                            [self messageReceived:output];
                        }
                    }
                }
                NSLog(@"receieved data: %@", receivedData);
            }
        }

            break;
        case NSStreamEventHasSpaceAvailable:
        {
            //Trust object is available here
             NSLog(@"Stream has space available");
        }
            break;
        case NSStreamEventErrorOccurred:
        {
            NSLog(@"has error occured: %@",[theStream streamError].localizedDescription);
        }
            break;
        case NSStreamEventEndEncountered:
        {
            [self close];
            NSLog(@"end encounter");
        }
            break;
        default:
            NSLog(@"Unknown event");
            break;
    }
}


식별 핸드 셰이크 문자열을 볼 것으로 예상했습니다.

그러나 아래 출력이 있습니다. \ ^ B로 서버 응답, 그게 뭔지 확실하지 않거나 올바르게 구문 분석하지 않습니다.

2019-07-15 17:01:06.180575-0700 ProxyTest[3222:881204] Opening streams.
2019-07-15 17:01:06.186495-0700 ProxyTest[3222:881204] connected
2019-07-15 17:01:06.194703-0700 ProxyTest[3222:881204] stream event 1
2019-07-15 17:01:06.194795-0700 ProxyTest[3222:881204] Stream opened
2019-07-15 17:01:06.194822-0700 ProxyTest[3222:881204] setting SSL
2019-07-15 17:01:06.195147-0700 ProxyTest[3222:881204] stream event 1
2019-07-15 17:01:06.195197-0700 ProxyTest[3222:881204] Stream opened
2019-07-15 17:01:06.195218-0700 ProxyTest[3222:881204] setting SSL
2019-07-15 17:01:06.265101-0700 ProxyTest[3222:881204] stream event 4
2019-07-15 17:01:06.265194-0700 ProxyTest[3222:881204] Stream has space available
2019-07-15 17:01:06.266564-0700 ProxyTest[3222:881204] stream event 2
2019-07-15 17:01:06.266639-0700 ProxyTest[3222:881204] has byte available
2019-07-15 17:01:06.266703-0700 ProxyTest[3222:881204] server said: \^B
2019-07-15 17:01:06.266801-0700 ProxyTest[3222:881204] message got it: \^B
2019-07-15 17:01:06.266841-0700 ProxyTest[3222:881204] \^B
2019-07-15 17:01:06.266948-0700 ProxyTest[3222:881204] receieved data: \^B
2019-07-15 17:01:11.331533-0700 ProxyTest[3222:881204] stream event 2
2019-07-15 17:01:11.331686-0700 ProxyTest[3222:881204] has byte available
2019-07-15 17:01:11.331799-0700 ProxyTest[3222:881204] receieved data:
2019-07-15 17:01:11.331912-0700 ProxyTest[3222:881204] stream event 16
2019-07-15 17:01:11.331973-0700 ProxyTest[3222:881204] Closing streams.
2019-07-15 17:01:11.332337-0700 ProxyTest[3222:881204] Disconnected
2019-07-15 17:01:11.332390-0700 ProxyTest[3222:881204] end encounter


  • 답변 # 1

    답변을 스스로 찾으십시오. NSMutableData에 저장 한 다음 NSMutableData를 16 진수로 변환하고 16 진수를 다시 읽을 수있는 문자열로 변환하면됩니다. 식별 문자열을 볼 수있었습니다.

관련 자료

  • 이전 amazon web services - Route53을 사용하여 한 최상위 도메인에서 다른 최상위 도메인으로 리디렉션하는 방법
  • 다음 java - radioGroup 버튼 안드로이드를 숨기는 방법