I have created a Private MSMQ and I am able to send messages to it. What I am now looking to do is to only allow a single user access to the queue and then send messages to that queue using that users credentials.
I am thinking about impersonating the user (I have an impersonator class) before sending the message but not sure how to do this.
any ideas on whats the best way to do this.
Oh! I am using C#.
What user will be running the executable? You can simply give that user access to the queue, and avoid impersonation altogether.
Impersonation is usually useful when you try to run different pieces of code as several different users. If you don't need several users, don't bother with impersonating at all.
Related
I'm looking for some advice here.
I have build a multi tenancy solution using RabbitMQ in C#.
It consists of a cloud solution that is pushing messages to the client applications through RabbitMQ.
Routing for RabbitMQ is setup using a routing key like: myapp.messagestream.<customercode>
All clients connect to RabbitMQ using the same username and password. Although the client code is obfuscated, it is still relatively simple to obtain the username and password. With this, theoratically, one could "guess" any other customer id and get the stream. Obviously, this is not what we want.
The way I would like to address this is to encrypt all messages using a encryption key per customer. This way, even if you have the username and password for RabbitMQ and you guessed a correct customer id, you would still not see any usable information.
Could anyone please share there insight on the above? Does it seem to be a good idea? or am I completely gone out of my mind?
Thanks in advance.
Even if the message is encrypted, it'd be consumed and removed from the queue. I guess that's not something you want to allow.
Consider creating different users and allowing them to read only from their own queues through authorization. You can connect it to a LDAP.
EDIT:
Hiding the messages in transit is always a good idea, but that can be achieved with SSL/TLS, no need to add another layer on top of that
I create a queue on my local machine in some other process as follows:
MessageQueue.Create(#".\private$\sampleQueue");
And in my reader process, I attach to it as follows:
var queue = new MessageQueue(#".\private$\sampleQueue");
When I try to do queue.Peek(), I get an access denied exception. I'm not on a domain, this is just my local workgroup computer. Any ideas?
MSMQ uses different protocols for it's work:
Pushing information (sending messages) uses MSMQ protocol.
Pulling information (receiving messages, getting properties, etc) using RPC protocol.
If it is not a simple permissions issue (which it is very likely to be) then you need this blog post:
Understanding how MSMQ security blocks RPC traffic
http://blogs.msdn.com/b/johnbreakwell/archive/2010/03/24/understanding-how-msmq-security-blocks-rpc-traffic.aspx
Cheers
John
If you r-click on the queue in Computer Management and select properties, do you have the appropriate permissions set on the Security tab?
The credentials used by the process that creates the queue must be different from the credentials of the process used to read the queue. If that is the way it must be, then you will need to specifically grant the needed read permissions on the queue after you create it.
I am looking into a way to more securely send emails from our application.
We are currently sending emails directly to an IIS SMTP server but are looking at ways to more securely deliver emails if the server goes down, restarts etc.
I was thinking a way to implement this would be to store the emails (with attachments) in a queue to be process by a separate process, or store the emails in the database to be then processed.
I was wanting to get some advice and any suggestions would be appreciated.
Thanks
We have a likewise case. We solved it by storing the emails in a database that keeps fault and retry status. We're using FreeSMTP to send the actual messages. Quicksoft also has a all-out product that handles errors itself and keeps its own message database if that is what you're looking for (not so free though ;-))
I made a simple notifier command line application in C#. Basically I use the windows task scheduler and set it up to run this command line application at a certain time.
When this time is hit the command line application is ran all notifications are grabbed from a database(using linq to sql) formatted and sent by smtp to the right people.
Now how should I handle these scenarios
A database error occurs
Solution: Send a email to the admin to notify them that it failed and to check it out.
A smtp error occurs
Solution: ?????
So these are really the two things that could go wrong. There could be different combination's of this.
Database error might occur and and smtp might occur too, Or only one or the other might occur.
So how to get this information to an admin or someone so they can fix it. I highly doubt that an admin would go and check every single day to see if the notification thing worked or not.
So basically how to make it fail safe or at least make it so that if something goes wrong a admin can come fix and it and just run the notifier manually and get everything back in sync.
You have a couple options.
Write the error information to a log. Make it a procedure for some operator to check the log every so often.
Have it call some other service?
However, if the database is used by more than just your app, it's entirely possible that someone else will notice. Same thing with the email server. If it's down, then I bet a lot of people will be making phone calls. Note that your situation precludes lost network connectivity (like a dead switch or misconfigured router).
Incidentally if it detects SMTP is back up, then it should notify someone that it was down for a given time period. Same thing about the database server.
Finally, ALL error conditions should be written to your system log. It's pretty trivial to write to the windows event logs. If your system administrators are following commonly accepted protocols they should be monitoring those pretty often anyway.
Logging an Error to the EventLog could also be an option, providing that the Admin either checks the EventLog regularly or that you have monitoring systems that aggregate those errors.
You could use an SMS gateway or attach a cellphone to the server and have it send a text message to an admin when something has gone horribly wrong.
But you can take this even further:
What if you lose network connectivity
(a switch or cable gone bad for
example)?
What if the power goes down
(when is the last time you tested the
UPS)?
Depending on your needs (and the business cost of not sending out these notifications in short notice), you may need a full-fledged monitoring solution.
So the main problem is that you do not know how to notify the admin in case of an SMTP server failure. You have several options, assuming the admin's e-mail account is not residing on the same server.
First option: You could set up a cgi mail script on another server and contact that via http to send the e-mail.
Second option: Use an smtp client and set it up to contact the receiver's smtp server for sending the e-mail directly (instead of going through the local smtp server).
BTW: Some e-mail providers offer text message notifications for e-mails originating from a certain address. That's very handy if the server goes down while the admin is away from his desk.
For your DB errors, you could hardcode in a (set of) email address for DB errors to be sent to.
As for the SMTP errors, you can either do a "send email when smtp recovers", or you have to have an alternate method for alerting your admins. This could be a backup SMTP server, a SMS gateway (as someone else mentioned), or even something such as someones desktop in the network popping up an alert if it doesn't receive some type of "everything is ok" alert/message from the box running the script.
I have an application with a static class that is capturing all errors that happens during the runtime (if its the case) and when process is done, it sends out an email with the list of errors so I or any other developers can address those errors.
However my problem is that McAfee is blocking the request, as if it was a kind of virus. I do not have rights on my machine to edit McAfee settings, is it possible to fix it through C# code?
Thank you
Probably McAfee is blocking outgoing connections on port 25 (SMTP), only allowing a white list of applications to send email.
What you can do is:
Put the email in a mailto:// url. Execute the mailto:// as if it is a normal command line. This will ask for input from the user, but you can create a nice template for the user. (syntax)
Send the email through your normal email client (Outlook, Notes), if they have an API for that.
Use a Http/Web based provider that has an API. Public ones are probably also blocked by McAfee. But you could create & host a service yourself. Be very carefull to only allow traffic from within your company.
Maybe you company has a "drop folder", where you can drop emails that are picked up by the email server.
Depending on what/why McAfee is flagging it, more than likely you will not be able to get around it.
You will want to see if you can find out if McAfee is flagging it due to the port being used, or if there is any other information as to why the individual message is not going.
No. And yes.
No, you can't force McAffee to not flag your email from code, if that's what you mean.
Yes, you can prevent McAffee or other virus scanners from flagging your emails as suspicious. Here are a couple of things I try to make sure of:
That your all addresses (especially from: and reply-to:) are valid.
That the the name you're sending from is actually the name of a the correct person in your active directory.
You could also ask your system administrators to put your "from:" address on a global whitelist so that it always goes to the client.
Are you attaching executables? Are you sure you aren't attaching any viruses? ;-)
From what I recall, I think McAfee has a list of programmes that are allowed to send emails, if your program is not added to this list, then your emails will not get sent.
This is a big support problem, as you will find your customers have a 101 different virus checkers all setup in different ways.
You may be able to setup a email server to use a none standard port, then send emails to that port.
For testing, attaching to the McAfee process with a debugger and then killing it can work well...