Need help accessing Apple APN server from a Windows vs2017 program - ios

Struggling with this for days. I'm in over my head. I developed an iOS enterprise app that I want to add Push Notifications to. I think I have the client side (iPhone) set up all right, but the Windows app (VB) I am developing to connect to the APNs server is giving me a lot of trouble.
Here's the very basic code I am using that I found somewhere on the internet, with the exception line shown:
Using client As New TcpClient()
client.Connect("gateway.sandbox.push.apple.com", 2195)
Using networkStream As NetworkStream = client.GetStream()
txtErrorMessages.AppendText("Client connected." & vbNewLine)
Dim clientCertificate As New X509Certificate(FileSystem.CurrentDirectory & "/apns-dev-key.p12", "abc123")
Dim clientCertificateCollection As New X509CertificateCollection(New X509Certificate(0) {clientCertificate})
' Create an SSL stream that will close the client's stream.
Dim sslStream As New SslStream(client.GetStream(), False, AddressOf ValidateServerCertificate, Nothing)
Try
[exception thrown here] sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, SslProtocols.Default, False)
Catch ex As AuthenticationException
txtErrorMessages.AppendText(String.Format("Exception: {0}", ex.Message) & vbNewLine)
If ex.InnerException IsNot Nothing Then
txtErrorMessages.AppendText(String.Format("Inner exception: {0}", ex.InnerException.Message) & vbNewLine)
End If
txtErrorMessages.AppendText(String.Format("Authentication failed - closing the connection.") & vbnewline)
client.Close()
Return
End Try
End Using
End Using
A google search brings up tons of different variations, but they are all apparently obsolete due to changes in the Push Notifications API over the years. I can't find anything that works, but this snippet at least gets me further than anything else has.
The exception:
I've tried a number of different variations on the .p12 file generated by the ID page on the Apple developer site, exported from the Mac's keychain, followed the steps from a number of different tutorials for converting to other formats (like .pem), or whatever, and nothing seems to work.
Interestingly, though, if I change the password string, the exception changes to The specified network password is not correct, which makes me think that it is at least recognizing the password.
Can anyone lead me out of this mess?
Thanks!

I discovered that I had overlooked loading the certificates into the development server, which is described here: https://arashnorouzi.wordpress.com/2011/04/13/sending-apple-push-notifications-in-asp-net-%e2%80%93-part-3-apns-certificates-registration-on-windows/

Related

Roblox: MarketplaceService:PromptGamePassPurchase error

So I have made a game pass, and in solo mode, if I check that the game pass (which I own) is owned, everything is fine. But when I test the game via the test tab, or upload it and connect with another account, the call in a server script:
clientWantsPass.OnServerEvent:connect(function(plr)
print("Prompting for purchase of " .. tostring(conf.changeSongPassID))
MarketplaceService:PromptGamePassPurchase(plr,conf.changeSongPassID)
end)
Produces the output on the server:
Prompting for purchase of 1059063949
And on the client:
04:14:25.798 - PurchasePromptScript: getProductInfo failed because MarketplaceService:getProductInfo() failed because HTTP 0 (HTTP 400 (HTTP/1.1 400 BadRequest)) Make sure a valid ID was specified
The pass does exist, I made it. calls to
game:GetService("GamePassService"):PlayerHasPass(plr, conf.changeSongPassID)
Return true for my character, and false for people who haven't bought it yet. I've tested putting the call to PromptGamePassPurchase on the server side, or in a local script. Always the same error.
Any help would be appreciated.
That happens because Roblox messed up the Gamepasses, and now they're a seperate 'category'.
You could try by using PromptPurchase, like MoonRunestar said?

Error trying to Connect to GMail with MailKit

I've got the following code...
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
{
ClientId = "<< MY CLIENT ID>>",
ClientSecret = "<<MY CLIENT SECRET>>"
},
new[] { "https://www.googleapis.com/auth/gmail.readonly" },
"<<EMAIL ADDRESS>>",
CancellationToken.None,
new FileDataStore("Mail2.Auth.Store")).Result;
using (var client = new ImapClient())
{
// THE CODE FAILS ON THIS NEXT LINE
client.Connect("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect);
client.Authenticate("<<EMAIL ADDRESS>>", credential.Token.AccessToken);
}
When run, the code fails on the indicated like with AuthenticationException: The remote certificate is invalid according to the validation procedure.
I initially thought that is was 'cos the account had 2-step authentication on. So, I set up another account ensuring it just used the regular authentication settings and I got the same error.
I have found a number of posts, here and elsewhere, that deal with this exception but they seem to deal with the issue of working with the SmtpClient() and here, as you can see from the code, I'm getting the error with the ImapClient().
Can anyone suggest what it is that may be the cause of the error? Is it GMail? MailKit? .NET? All of the above?
The problem is that your system does not accept the GMail's SSL certificate.
You can override client.ServerCertificateValidationCallback.
A very simple example of a solution might look like this:
client.ServerCertificateValidationCallback = () => true;
Obviously that means that if anyone ever spoofed imap.gmail.com, your software would get caught in a MITM attack, so that's not ideal.
You'll likely want to match the certificate's thumbprint against a known thumbprint or else add the certificate to your local certificate store and assign a trust level to it.

Yodlee API return error with data encrypted

I'm building an app using yodlee and rails, everything works fine on sandbox, the problem it's when I use the live env, with the PKI feature.
I'm getting my API key from here
Then I'm using these lines of code to encrypt the sensitive information (username/password/pin)
key= public_key
rsa_key = OpenSSL::PKey::RSA.new(key.keyAsPemString)
key.keyAlias + ":" +Base64.encode64(rsa_key.public_encrypt(value_to_encrypt))
I send the request but I'm getting this
{"errorCode"=>"Y400", "errorMessage"=>"Decryption failure for FieldInfo:FieldInfoSingle: {FieldInfo: name=\"LOGIN\" displayName=\"null\" editable=true optional=false helpText=\"null\" valuePattern=\"null\" } defaultValue=\"null\" value=\"\" validValues=[null] displayValidValues=[null] valueIdentifier=\"null\" valueMask=\"null\" fieldType=\"TEXT\" validationRules=[null] size=null maxlength=null userProfileMappingExpression=null fieldErrorCode=null fieldErrorMessage=null ", "referenceCode"=>"RB_3cf12f35-05d3-4d87-a1f9-edcfc62df3d2"}
Any ideas?
The only difference from the official Java version of the encryption code seems to be the final encoding. It should be hex-encoded, not Base64-encoded. Try this instead:
key.keyAlias + ":" + Digest.hexencode(rsa_key.public_encrypt(value_to_encrypt))
It seems like in your live environment PKI feature is not enabled correctly. Please ask Yodlee support team to either enable or disable PKI based on your need. Once they do that it should work as expected.

Problem attaching file programmatically to blackberry Email Client

I am attempting to attach an excel spreadsheet to an email programmatically, and then launch the default blackberry email client with the message as an argument. Unfortunately, I receive the error: "Email service does not support these types of attachments. Change the Send Using field or remove the attachments." The send button is not present, and there is no "Send" option in the menu; this is blocking the ability to send the email.
This error occurs when I load the package onto my physical blackberry phone, as well as in the simulator.
I am able to send the email without a hitch if I use the API instead (the commented transport.send line).
Any and all input would be greatly appreciated, and if I've overlooked some details please let me know.
public Email()
{
try{
message = new Message();
multipart = new Multipart(); //Multi part can hold attachment AND body (and more)
subject = "Service Change Request";
multipart.addBodyPart( new TextBodyPart( multipart, "Hi XXXXXX, \n Here are the details for CLIENT" ) );
byte[] data = null;
InputStream stream = MyAPP.getUiApplication().getClass().getResourceAsStream("/blank_form.xls");
data = IOUtilities.streamToBytes(stream);
stream.close();
multipart.addBodyPart( new SupportedAttachmentPart( multipart, "application/octet-stream", "ServiceUpdate.xls", data ) );
Address recipients[] = new Address[1];
recipients[0]= new Address("*******#gmail.com", "user");
message.setSubject(subject);
message.setContent( multipart );
message.addRecipients(Message.RecipientType.TO, recipients);
//Transport.send(message);
}catch(Exception e){
}
}
public void send(){
Invoke.invokeApplication( Invoke.APP_TYPE_MESSAGES, new MessageArguments( message ) );
}
EDIT:
The error comes up because the simulator has no email account configured. It should work just fine on any phone that has an email account properly configured.
I hope this helps and I am not too late to lend a hand on this post.
I've worked with attachments before, and they are a pain to work with in Blckberry.
The only issue I can think of is the MIME type you are trying to use.
"Application/octet-stream", try using the MIME corresponding to the extension of the attachment, for example "application/excel" for .xls files. You can find the complete list here , its the longest one I could find.
There are also some issues with the Blackberry email service and attachments that are mentioned on several Knowledge Base Articles on the official Developers page like this one, they sometimes say that the attachments have to be prefixed with "x-rimdevice" in the file name, like "x-rimdevice-serviceupdate.xls". Although I'm not really sure this affects on outgoing email, but I thought it was worth mentioning.
By the way, I'm trying to use your code for an App I'm coding right now, so I'm kind of hoping it works.

Trouble with authlogic_rpx

I'm trying to run http://github.com/tardate/rails-authlogic-rpx-sample (only rails version was changed) but get error message http://gist.github.com/385696, when RPX returns information after successful authentication via Google Account. What is wrong here? And how I can fix it?
The code was successfully tested with rails 2.3.3 by its author: http://rails-authlogic-rpx-sample.heroku.com/
I run on Windows with cygwin and rails (2.3.5), rpx_now (0.6.20), authlogic_rpx (1.1.1).
Update
In several hours RPX rejected my app http://img96.imageshack.us/img96/2508/14128362.png
Update2
The same error message ( http://gist.github.com/386124) appears with http://github.com/grosser/rpx_now_example , but in this case RPX allows me to sign in (so far).
Solved
See below
Got error: Invalid parameter: apiKey (code: 1), HTTP status: 200
You have to first register your RPX app at http://www.RPXnow.com and set its name. You'll be assigned an API key which you should set in the config/environment.rb file:
RPX_API_KEY = ENV["RPX_API_KEY"]
RPX_APP_NAME = "your_app_name_here!"
Or: Read slide 35: http://www.slideshare.net/tardate/srbauthlogicrpx
You shouldn't have any constraints enforced at the database level.
The reason was trailing \r character in my API key. Apparently, non of the steps did key trimming and the exception was not processed in a good way.

Resources