<commit_before>require 'openssl'
require 'socket'

module ApnsSimple
  class Client

    attr_reader :certificate, :passphrase, :host, :port

    COMMAND = 8
    CODES = {
      0 => 'No errors encountered',
      1 => 'Processing error',
      2 => 'Missing device token',
      3 => 'Missing topic',
      4 => 'Missing payload',
      5 => 'Invalid token size',
      6 => 'Invalid topic size',
      7 => 'Invalid payload size',
      8 => 'Invalid token',
      10 => 'Shutdown',
      255 => 'Unknown error'
    }

    def initialize(options)
      @certificate = options.fetch(:certificate)
      @passphrase = options[:passphrase] || ''
      gateway_uri = options[:gateway_uri] || 'apn://gateway.push.apple.com:2195'
      @host, @port = parse_gateway_uri(gateway_uri)
    end

    def push(notification)
      begin
        ctx = OpenSSL::SSL::SSLContext.new
        ctx.ssl_version = :TLSv1_2
        ctx.key = OpenSSL::PKey::RSA.new(certificate, passphrase)
        ctx.cert = OpenSSL::X509::Certificate.new(certificate)

        sock = TCPSocket.new(host, port)
        ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
        ssl.connect
        ssl.write(notification.payload)
        ssl.flush

        if IO.select([ssl], nil, nil, 1) && error = ssl.read(6)
          command, status, _index = error.unpack("ccN")
          notification.error = command == COMMAND ? "#{status}: #{CODES[status]}" : "Unknown command received from APNS server: #{command}"
        end
      ensure
        ssl.close if ssl
        sock.close if sock
      end
    end
<commit_msg>Try to use :SSLv3 mode.<commit_after>require 'openssl'
require 'socket'

module ApnsSimple
  class Client

    attr_reader :certificate, :passphrase, :host, :port

    COMMAND = 8
    CODES = {
      0 => 'No errors encountered',
      1 => 'Processing error',
      2 => 'Missing device token',
      3 => 'Missing topic',
      4 => 'Missing payload',
      5 => 'Invalid token size',
      6 => 'Invalid topic size',
      7 => 'Invalid payload size',
      8 => 'Invalid token',
      10 => 'Shutdown',
      255 => 'Unknown error'
    }

    def initialize(options)
      @certificate = options.fetch(:certificate)
      @passphrase = options[:passphrase] || ''
      gateway_uri = options[:gateway_uri] || 'apn://gateway.push.apple.com:2195'
      @host, @port = parse_gateway_uri(gateway_uri)
    end

    def push(notification)
      begin
        ctx = OpenSSL::SSL::SSLContext.new
        ctx.ssl_version = :SSLv3
        ctx.key = OpenSSL::PKey::RSA.new(certificate, passphrase)
        ctx.cert = OpenSSL::X509::Certificate.new(certificate)

        sock = TCPSocket.new(host, port)
        ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
        ssl.connect
        ssl.write(notification.payload)
        ssl.flush

        if IO.select([ssl], nil, nil, 1) && error = ssl.read(6)
          command, status, _index = error.unpack("ccN")
          notification.error = command == COMMAND ? "#{status}: #{CODES[status]}" : "Unknown command received from APNS server: #{command}"
        end
      ensure
        ssl.close if ssl
        sock.close if sock
      end
    end

{'fraction_non_alphanumeric': 0.13181242078580482, 'fraction_numerical': 0.016476552598225603, 'mean_word_length': 2.4692307692307693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3711351', 'n_tokens_mistral': 1006, 'n_tokens_neox': 959, 'n_words': 244}